当我访问 ListFragment 中的菜单项时info.position
,我得到 NullPointerEx。有谁知道为什么?
listView.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
if (mCurrentActionMode != null) {
return false;
}
mCurrentActionMode = getSherlockActivity().startActionMode(
mContentSelectionActionModeCallback);
view.setSelected(true);
return true;
}
});
}
private ActionMode.Callback mContentSelectionActionModeCallback = new ActionMode.Callback() {
@Override
public boolean onActionItemClicked(ActionMode actionMode, MenuItem item) {
switch (item.getItemId()) {
case R.id.delete:
delete(item);
actionMode.finish();
return true;
}
return false;
}
}
private void delete(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
Log.i("test", String.valueOf(info.position)); //NPE
}