小编Gra*_*y-M的帖子

使用ContextMenuInfo的空值调用onCreateContextMenu

我正在尝试使用ContextMenu。我已经使用SimpleCursorAdapter为一个简单的ListActivity成功完成了此操作。

继续,我想用CursorAdapter替换SimpleCursorAdapter,但仍然保留ContextMenu的行为,因此我添加了两个强制性重写功能bindView和newView

public View newView(Context context, Cursor cursor, ViewGroup parent) {
    View view = mLayoutInflater.inflate(R.layout.check_row, parent, false);
    registerForContextMenu(view);
    return view;
}
Run Code Online (Sandbox Code Playgroud)

请注意registerForContextMenu,它取代了ListActivity的onCreate方法中的registerForContextMenu(getListView())。我发现有必要调用onCreateContextMenu(...)

除提供给onCreateContextMenu(...)的ContextMenuInfo参数外,所有这些工作(使用预期的小部件创建的行,其上的回调正常工作等)现在为空-阻止我访问rowId。

还有另一个技巧可以执行-也许在CursorAdapter的bindView(...)方法中?

android listview cursor

5
推荐指数
1
解决办法
3469
查看次数

标签 统计

android ×1

cursor ×1

listview ×1