0

当我访问 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
        }
4

1 回答 1

0

在我看来,这超出了您尝试使用它的范围。

您应该获得该位置onItemLongClick并将其传递给您的其他方法到您的删除功能。

于 2012-06-03T15:12:29.067 回答