I am trying to create a ContextMenu with a button. For some reason, it is not working. Can anyone tell me what is wrong with my code?
This is the picture_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/take_from_gallery"
android:title="@string/str_take_from_gallery"/>
<item
android:id="@+id/take_picture"
android:title="@string/str_take_picture"/>
<item
android:id="@+id/delete_picture"
android:title="@string/str_delete_picture"/>
</menu>
and this is the java code:
camera_button= new Button(this);
camera_button.setLongClickable(true);
registerForContextMenu(camera_button);
public void onCreateContextmenu(ContextMenu menu, View v,ContextMenuInfo menuInfo)
{
MenuInflater inflater= getMenuInflater();
inflater.inflate(R.menu.picture_menu, menu);
super.onCreateContextMenu(menu, v, menuInfo);
}
public boolean onContextItemSelected(MenuItem item)
{
AdapterContextMenuInfo info= (AdapterContextMenuInfo) item.getMenuInfo();
switch (item.getItemId())
{
case R.id.take_from_gallery:
return true;
case R.id.take_picture:
return true;
case R.id.delete_picture:
return true;
default:
return super.onContextItemSelected(item);
}
}
All I need right now is to make this work.
Thanks!
Finally the problem was really silly. A was mispelling the “onCreateContextMenu” function. Thanks anyway!