Android 数据库未更新或删除
所以基本上我的数据库工作了一段时间(虽然非常小故障,基本上必须重新启动我的应用程序才能看到列表视图中的更改)。
这是一个由两部分组成的问题:
我使用自定义适配器并用于
ea.notifyDataSetChanged();
尝试更新我的适配器。但我认为问题在于数组也没有更新。
List<String> rList = db.selectAllReceive();
receiveMessages = rList.toArray(new String[rList.size()]);
我应该只更新适配器内的数组吗?
第二部分:
db.delete(clicked);
Toast.makeText(getBaseContext(), "Deleted Row: " + clicked, Toast.LENGTH_SHORT);
Log.i("ContextMenu", "[MainAct.Class] Clicked DELETE");
ea.notifyDataSetChanged();
这是我的 onContextItemSelected() 中的代码。我得到了日志,但没有得到 Toast 或注意到任何数据库删除。
也许这一切都归结为数组更新得不够?我应该创建一个方法来更新数组并在之后使用它吗?
谢谢
So basically my database was working for a little while (very glitchy though, had to basically restart my application to see the change in my list view).
This is a two part question:
I use a customized adapter and use
ea.notifyDataSetChanged();
to try and update my adapter. But I think the problem lies that the arrays don't update as well.
List<String> rList = db.selectAllReceive();
receiveMessages = rList.toArray(new String[rList.size()]);
Should I just update the array inside the adapter?
Part two:
db.delete(clicked);
Toast.makeText(getBaseContext(), "Deleted Row: " + clicked, Toast.LENGTH_SHORT);
Log.i("ContextMenu", "[MainAct.Class] Clicked DELETE");
ea.notifyDataSetChanged();
This is my code that is within my onContextItemSelected(). I get my log, but I do not get a Toast or notice any database deletion.
Maybe it all comes down to the fact that the array is not updated enough? Should I create a method to update the arrays and use it after it?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果没有整个班级,很难确定,但我认为存在线程问题。 Toast 消息未显示表明了这一点(我认为),我会检查您是否正确执行线程来处理数据库更新和列表视图更新。
Without the whole class/classes, hard to say for sure, but I would presume a threading issue. The Toast message not showing up suggests this (I think), I would check into if you're doing the threading properly for dealing with the database updates and list view updating.
使用 mListView.setAdapter(adapter) 可以解决所有问题,也许有点效率问题,但如果数据源不大,那就更难了。
using mListView.setAdapter(adapter) can solve all of thing,maybe a little Efficiency problem,but if the datasouce not big,It's conld bear.