看看下面的代码......为什么我的上下文菜单没有被创建???这可能是什么原因......?
@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);
}
}
这是上下文菜单显示器中 xml 文件的代码
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>