have a look at the code below…why isnt my context menu being created ??? what may b the cause of this…?
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflator = getMenuInflater();
inflator.inflate(R.menu.contextmenudisplayer, menu);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
switch(item.getItemId())
{
case R.id.delete:
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
String s = (String) ((Cursor) getListView().getItemAtPosition(info.position))
.getString(2);
Log.v("ID is", s);
default:
return super.onContextItemSelected(item);
}
}
and here is the code of the xml file from the context menu displayer
contextmenudisplayer.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/delete"
android:title="Delete Message">
</item>
<item
android:id="@+id/forward"
android:title="Forward">
</item>
</menu>
You need to register the menu with this method:
http://developer.android.com/reference/android/app/Activity.html#registerForContextMenu(android.view.View)
Read this page, it explains everything:
http://developer.android.com/guide/topics/ui/menus.html