gpt4 book ai didi

android - onCreateContextMenu 被 ContextMenuInfo 的 null 值调用

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:59:49 31 4
gpt4 key购买 nike

我正在尝试使用上下文菜单。我已经使用 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;
}

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

除了提供给 onCreateContextMenu(...) 的 ContextMenuInfo 参数现在为 null - 阻止我访问 rowId 之外,所有这些都有效(使用预期的小部件创建的行,它们的回调工作等)。

是否还有其他技巧可以执行 - 也许在 CursorAdapter 的 bindView(...) 方法中?

最佳答案

我正在回答这个问题 - 但我要指出“commonsware.com”提供了线索和方向,见上文。

问题

  • 在行布局中使用 CheckBox 会影响上下文菜单的使用
  • 我认为,Che​​ckedTextView 旨在用于多选,它不适合初始化选中状态。

我采用的解决方案做了以下事情

  1. 使用 CheckedTextView
  2. 从 CursorAdapter 扩展以在 bindView(...) 期间初始化选中状态
    注意:这也必须设法显示正确的图标
  3. 在 onListItemClick(...) 中管理 CheckedTextView 的状态并将其记录在 dBase 中,不要忘记更新光标。

关于android - onCreateContextMenu 被 ContextMenuInfo 的 null 值调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1718765/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com