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
}