0

I have verified that setOnClickListener is being called, so why doesn't the button click do anything in 2.3? It works fine in 4.1. I am testing on emulators with cameras emulated. I have tried making sure the button is clickable in xml, but that didn't do anything.

ImageButton mPhotoButton = null;
if (v != null) {
    mPhotoButton = (ImageButton) v.findViewById(R.id.crime_imageButton);
}
if (mPhotoButton != null) {
    mPhotoButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent i = new Intent(getActivity(), CrimeCameraActivity.class);
            startActivityForResult(i, REQUEST_PHOTO);
        }
    });
}

xml:

<ImageButton
    android:id="@+id/crime_imageButton"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:src="@android:drawable/ic_menu_camera"/>

setting button to disabled, why is this executing only in 2.3?:

PackageManager pm = getActivity().getPackageManager();
if (pm != null) {
    if (!pm.hasSystemFeature(PackageManager.FEATURE_CAMERA) && !pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT)) {
        if (mPhotoButton != null) {
            mPhotoButton.setEnabled(false);
        }
    }
}
Adam Johns
  • 35,397
  • 25
  • 123
  • 176
  • can you show where you have this code in fragment or activity? – Raghunandan Jan 13 '14 at 15:30
  • Are you sure you're not drawing anything on top of it? – Matt Jan 13 '14 at 15:30
  • the only thing visible here seems that your if(mPhotoButton != null) is actually null so it never let it happen! – Saqib Jan 13 '14 at 15:31
  • I'm guessing you are setting the listener in a fragment. If you say you are sure that you capture the click events, your problem is with startActivityForResult(i, REQUEST_PHOTO); – Barışcan Kayaoğlu Jan 13 '14 at 15:31
  • @Saqib it is probably not null because that way listener would not invoke click event. – Barışcan Kayaoğlu Jan 13 '14 at 15:33
  • do you mean your onClick event is triggering??? if so then what? doesn't code inside that work? – Saqib Jan 13 '14 at 15:34
  • ok I have found the root of the problem, but I am still not sure why this only occurs in 2.3 emulator and not 4.1. I have added the section of code that causes the button to be disabled. Still not sure why it is being executed though. – Adam Johns Jan 13 '14 at 15:47
  • ok it turns out, the button is disabled per the code above in all emulators running < 4.0. Apparently camera emulation not allowed pre api 14. – Adam Johns Jan 14 '14 at 15:23

0 Answers0