I'm trying to bring up an alert dialog box when one of my OptionsMenuItems is clicked. Proceed with operation if user clicks "yes", cancels if clicks no. I just don't know how to do the code. This is what I have:
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId()) {
case R.id.exit:
this.finish();
return true;
case R.id.about:
Intent i = new Intent(this, AboutActivity.class);
this.startActivity(i);
case R.id.skip:
AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
// set the message to display
alertbox.setMessage("The yoga pose will be skipped from now on!").show();
alertbox.setCancelable(true);
alertbox.setNegativeButton("no").setPositiveButton("OK", new DialogClicklistener() {
// click listener on the alert box
public boolean onClick(DialogInterface arg0, int arg1) {
// the button was clicked
boolean success = myDbHelper.setSkip(PoseID);
SetImageView2(myDbHelper);
return success;
}
});
// add a neutral button to the alert box and assign a click listener
alertbox.setCancelable(true).set(onCancelListener) {
// click listener on the alert box
public boolean onClick(DialogInterface arg0, int arg1) {
// the button was clicked
}
});
// show it
alertbox.show();
default:
return super.onOptionsItemSelected(item);
}
}
The following is directly from the app I'm currently working on. It brings up an AlertDialog which then takes the user to a different activity (after they enter a password). Please let me know if I can clarify anything about it.
Edit: whole method now included.