what about showing popup menu when clicking onthat item ?
here is the code :
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_notifi) {
// here we show the popup menu
popup();
}
return super.onOptionsItemSelected(item);
}
public void popup(){
PopupMenu popup = new PopupMenu(MainActivity.context, v); //the v is the view that you click replace it with your menuitem like : menu.getItem(1)
popup.getMenuInflater().inflate(R.menu.medecin_list_menu,
popup.getMenu());
popup.show();
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item2) {
switch (item2.getItemId()) {
case R.id.Appeler:
//do somehting
break;
case R.id.EnvoyerMsg:
//do somehting
break;
case R.id.AfficherDet:
//do somehting
break;
case R.id.Afficher:
//do somehting
break;
case R.id.AvoirRdv:
//do somehting
break;
default:
break;
}
return true;
}
});
}
});
}
and here is the medecin_list_menu (my menu)
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/Appeler"
android:title="@string/Appeler" />
<item
android:id="@+id/EnvoyerMsg"
android:title="@string/envoyerMsg" />
<item
android:id="@+id/Afficher"
android:title="@string/Afficher" />
<item
android:id="@+id/AvoirRdv"
android:title="@string/avoirRdv" />
<item
android:id="@+id/AfficherDet"
android:title="@string/afficherDet" />
</menu>
Last Edit:
see this tutorial http://www.androidhive.info/2013/11/android-working-with-action-bar/