Android 数据库未更新或删除

发布于 2024-11-18 07:53:49 字数 739 浏览 7 评论 0原文

所以基本上我的数据库工作了一段时间(虽然非常小故障,基本上必须重新启动我的应用程序才能看到列表视图中的更改)。

这是一个由两部分组成的问题:

我使用自定义适配器并用于

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寄居者 2024-11-25 07:53:49

如果没有整个班级,很难确定,但我认为存在线程问题。 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.

银河中√捞星星 2024-11-25 07:53:49

使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文