質問

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?

役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top