I am beginner in Android. I have some problem which can not solve. I use Fragment with ListView, SimpleCursorAdapter and LoaderCallbacks. I get datas from database by View and fill the ListView. I want to delete the item from ListView by ContextMenu, but get id of every item = 0. If I use a query from usual table (not my View), my contextMenu works and selected items is deleted. How should I do a query from multiple tables to get datas I need and do not use the View? Cause if I use the query from multiple tables Android needs a rowid, but query from multiple tables does not allow to request a rowid neither from View or from usual table. LogCat says _id no such column. Thanks of any ideas!


使用代码示例编辑您的帖子。您是否为列表中的每个项目提供一个 id?

抱歉,我已经发现问题了。建议我重新创建一个 ContextMenu,如下所示: AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; 光标cursor = mAdapter.getCursor(); 光标.moveToPosition(info.position); myItemId = Cursor.getInt(cursor.getColumnIndex("idUserRecord")); 然后我在 onContextItemSelected 中使用了 myItemId 。通过 myItemId 的值从数据库中删除该行,然后设置 myItemId = 0 并使用 getLoaderManager().getLoader(0).forceLoad(); 并且 ListView 可以工作!感谢您的关注

好的!使用解决方案更新您的帖子。

我已经在之前的评论中写了解决方案。

我知道,但很难阅读评论中的代码,请使用解决方案编辑您的帖子。