我正在以与我一直这样做相同的方式编写代码并且看不到我错在哪里:
@Override
public void onCreate(){
...
this.registerForContextMenu(lv);
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.context_menu_device_item_remove, menu);
}
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/context_menu_item_remove_id"
android:title="Remove" />
<item android:id="@+id/context_menu_item_clear_all_id"
android:title="Clear all" />
</menu>
如您所见..效果是:
由于使用了 AdapterContextMenuInfo.position,应用程序在单击第三个或第四个元素时崩溃:
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
System.out.println("## info.position: "+info.position);
...
你有没有遇到过这种情况?& 你是如何逃脱的?