i am implementing side navigation bar, i`ll create onOptionsItemSelected
() method inside method codes are
`
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (toggle.onOptionsItemSelected(item))return true;
switch (item.getItemId()){
case R.id.logoutId:
Toast.makeText(getApplicationContext() , item.getItemId() , Toast.LENGTH_SHORT).show();
case R.id.homeId:
Toast.makeText(getApplicationContext() , item.getItemId() , Toast.LENGTH_SHORT).show();
case R.id.profileId:
Toast.makeText(getApplicationContext() , item.getItemId() , Toast.LENGTH_SHORT).show();
case R.id.settingsId:
Toast.makeText(getApplicationContext() , item.getItemId() , Toast.LENGTH_SHORT).show();
}
return super.onOptionsItemSelected(item);
}
`
every thing is fine but clicking action not working.? plz help me!!!
update:
Action bar item worked well but
but Side Navigation Item not working? plz tell me the solution and why its not working ?
You should return true when you handle menu item click. Try to add the return statement on each case.
For example:
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()){
case R.id.logoutId:
Toast.makeText(getApplicationContext() , item.getItemId() , Toast.LENGTH_SHORT).show();
return true;
case R.id.homeId:
Toast.makeText(getApplicationContext() , item.getItemId() , Toast.LENGTH_SHORT).show();
return true;
case R.id.profileId:
Toast.makeText(getApplicationContext() , item.getItemId() , Toast.LENGTH_SHORT).show();
return true;
case R.id.settingsId:
Toast.makeText(getApplicationContext() , item.getItemId() , Toast.LENGTH_SHORT).show();
return true;
case default:
return super.onOptionsItemSelected(item);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.