I have a button, and I want it to be enabled only when the user has choosen an image
I made this code, but it doesn’t work 🙁
Code updated
Help please ..
the user can get an image by selecting one from the gallery, or capturing one .. if that is related
UPDATE::
these are my camera and gallery code
btnGallery.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
btnNext.setEnabled(true);
}
});
btnCamera.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent, RESULT_LOAD_IMAGE);
btnNext.setEnabled(true);
}
});
and this is the next button code
btnNext.setEnabled(false);
btnNext.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
MpClick.start();
if (btnNext.isEnabled() == false)
{
Toast.makeText(StartActivity.this,
"Please get an image first.", Toast.LENGTH_LONG)
.show();
}
else
{
Intent next = new Intent(StartActivity.this, Option.class);
startActivity(next);
}
}
});
}
sometimes it takes u to the Option activity and sometimes it doesn’t, and the message never shows ..
I want the message shows when u click on the next button and u didn’t choose an image
but if u choose an image it’ll take u to the Option activity
There are a few problems here:
ifstatements with;… don’t do this.setEnabledinstead ofisEnabled.().else if, since you’re only checking the opposite of the first conditional.elsewill do just fine here.You should instead be using: