I have a context menu. The function v.getId() is supposed to return the id, but does not - instead it returns 'false'.
Here is my code:
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle("Options");
menu.add(0, v.getId(), 0, v.getId());
menu.add(0, v.getId(), 0, "Save Notification");
}
@Override
public boolean onContextItemSelected(MenuItem item) {
if(item.getTitle()=="Save Ringtone"){function1(item.getItemId());}
else if(item.getTitle()=="Save Notification"){function2(item.getItemId());}
else {return false;}
return true;
}
public void function1(int id){
//Stuff
}
public void function2(int id){
if (id == R.raw.tedcake){
Toast.makeText(this, id, Toast.LENGTH_SHORT).show();
}
The buttons were registered for a context menu elsewhere in the code.
Why is it returning false?
Thanks.