1

I've tried implementing an onClickListener on a CameraFragment, however, it never seems to be called. I am probably missing something quite simple. Does anyone have any ideas?

public class CWACCameraFragment extends CameraFragment implements OnClickListener {

//...

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    takePicture();
    Toast.makeText(getActivity(),"click",
        Toast.LENGTH_LONG).show();
}

Is there a way to ensure that the onClick event occurs?

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
buckettt
  • 319
  • 2
  • 12
  • You cannot put a click listener on a fragment. Please show where and how you are calling `setOnClickListener()`. – CommonsWare Oct 06 '13 at 20:31
  • In onStart I just call getView().setOnClickListener(this); Which is probably comepletely the wrong way to do it – @CommonsWare – buckettt Oct 06 '13 at 20:47
  • In theory that should work, assuming that `getView()` does not return `null`. By `onStart()`, the fragment's `View` should be ready. – CommonsWare Oct 06 '13 at 20:52

1 Answers1

1

In the demo app, I added the following to DemoCameraFragment:

  @Override
  public void onStart() {
    super.onStart();

    getView().setOnClickListener(new View.OnClickListener() {

      @Override
      public void onClick(View v) {
        Log.e(getClass().getSimpleName(), "got here");
      }
    });
  }

Log messages showed up just fine. Hence, AFAICT, your approach works, so perhaps there is some bug in how you wired in the click listener.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491