menu item is not displaying dialog box below is my code when user click on menu item it should take him to login page where to add that code.
public boolean onOptionsItemSelected(MenuItem item, int id) {
switch (item.getItemId()) {
case R.id.Login:
startActivity(new Intent(this, Login.class));
return true;
case R.id.About:
startActivity(new Intent(this, About.class));
return true;
case R.id.Post_Ads:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure you want to exit?")
.setCancelable(false);
AlertDialog alert = builder.create();
alert.show();
startActivity(new Intent(this, Login.class));
return true;
}
return super.onOptionsItemSelected(item);
}
Try this , it should work:
There is no method called
public boolean onOptionsItemSelected(MenuItem item, int id)in theActivityclasstohandle option menu's.The method to handle such events is
onOptionsItemSelected(MenuItem).For your menu items to getting displayed, you have to use following method too,
Check whether you have implemented this method also or not,
And a small correction,
You have implemented the following Alertdialog method,
You haven’t provided any ok or cancel button here,
And also you made it setCancellable(false). So User cannot choose any options here.
So i am suggesting you to give Ok and Cancel Button here and do what you want to do inside the onClick() method. Like the following example:
Hope, It might be helpful.