Android的DB装载聊天的聊天应用程序 [英] Android db loading chat for chat application

查看:177
本文介绍了Android的DB装载聊天的聊天应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建一个聊天应用程序,我需要指导一点点。我使用的SQLite数据库来存储聊天,因为它的用武之地。我希望我的活动,当它打开时,从该特定聊天负荷的聊天记录,并继续刷新新的聊天输入(我的主要问题是如何做的我去这样做)。

I'm creating a chat application and I need a little bit of guidance. I am using a sqlite database to store the chat as it comes in. I want my Activity, when it's open, to load the chat history from that particular chat and to continue to refresh as new chat is entered (my main question is how do I go about doing this).

我应该使用的CursorAdapter包含聊天的谈话查询的inital光标并将其设置为为ListView适配器?我已经试过这一点,但是当我插入到数据库中的数据不会刷新。

Should I use a CursorAdapter with an inital cursor of a query containing the chat for that conversation and set it as the adapter for the ListView? I have tried this, but the data doesn't refresh when I insert into the database.

我知道我没有提供任何code,但一般的谈话的最好办法就是去了解,这是值得欢迎的。谢谢!

I know I didn't provide any code, but general conversation about what the best way is to go about this is welcome. Thanks!

让我还提到,我需要这个工作,为Android 2.3.3(API 10)和最多(CursorLoader和所有不可用,直到11 API,我也读了一些关于)。另一件事是我可以做的是使用ArrayAdapter,并直接添加聊天记录成(如果该活动是打开的),并把它插入到数据库中的情况下,它不会再上onResume(),清除一个ArrayAdapter和查询所有康沃一次,重新进行添加每个。这将是最优化的方式?

Let me also mention that I need this to work for android 2.3.3 (API 10) and up (CursorLoader and all that is not available until API 11 which I did read a little about). The other thing I can do is use an ArrayAdapter and add chats directly into that (if the activity is open) and also insert it into the db in case it is not and then on onResume(), clear the ArrayAdapter and query all the convo once and readd each. Would this be the most optimal way?

推荐答案

看一看LoaderManager。真的简单,不正是你想要的。 它可用于使用2.3.3的兼容性库。

Have a look at LoaderManager. Really simple and does exactly what you want. It is available for 2.3.3 using the compatibility library.

http://developer.android.com/reference/android/app/ LoaderManager.html

这篇关于Android的DB装载聊天的聊天应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆