I'm developing an Android app in which I have two images on a screen, client and your vehicle.
I want to show a menu by giving a long click on both images and so on, by clicking on both imageView the same menu is shown, however, how do I differentiate between them? the onContextItemSelected method?
This is the code:
-
I registered to show the menu in both imageView
@Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.tela_cliente_cadastrar); registerForContextMenu(helper.img_clienteClick()); registerForContextMenu(helper.img_veiculoClick());
...
-
I created the menu
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { menu.setHeaderTitle("Opções"); menu.add(Menu.NONE, MENU_TAKE_PHOTO, 0, "Take photo"); menu.add(Menu.NONE, MENU_VIEW_PHOTO, 0, "View"); menu.add(Menu.NONE, MENU_DEL_PHOTO, 0, "Delete");
}
And here's the problem because I could not find a way to discern one from the other:
@Override
public boolean onContextItemSelected(MenuItem item) {
switch(item.getItemId()){
case MENU_TAKE_PHOTO: {
helper.startCameraForClient();
//or helper.startCameraForVehicle();
}
case MENU_VIEW_PHOTO: {
Intent intent = new Intent(getBaseContext(), FotoFullscreen.class);
intent.putExtra("image", PHOTO_CLIENT);
//OR intent.putExtra("imagem", PHOTO_VEHICLE);
startActivity(intent);
}
case MENU_DEL_PHOTO: {
}
}
return super.onContextItemSelected(item);
}