请教关于XListView的 下拉更新的有关问题
请问关于XListView的 下拉更新的问题
请问,使用XListView的显示从网络数据库获取的数据。
刚开始调用: updatenetworkdata ()获取网络数据库最新的数据。比如说 第一次调用后merChatList得到的数据是:
a
b
c
那么当下拉屏幕的时候,就会调用 onRefresh() 函数 在次函数里边 再次调用updatenetworkdata ()函数。假设这时候 网络数据库没有更新,那么这时候
merChatList的数据为:
a
b
c
a
b
c
也就是重复了。
本来就想 当下拉更新的时候, //mMemberChatList.clear();
先清除数据,然后获取最新的数据的。
但是这样重新取数据的话,会很费时的。再说 有时候 网数据库只更新了 一条数据,如果把之前删除了,再取就好像
有点不妥。
请会的朋友帮忙回复下,这个应该怎么处理,谢谢啦
public void updatenetworkdata (final String url, final MemberChatCallBack callBack){
new Thread() {
public void run() {
//mMemberChatList.clear();
String objectString = objectToString();
String info = CustomHttpClient.postByHttpClient(objectString);
try {
JSONObject jsonObject = new JSONObject(info);
String total = jsonObject.getString("total");
JSONArray jsonArray = jsonObject.getJSONArray("data");
for( int i=0;i<jsonArray.length();i++ ) {
JSONObject item = jsonArray.getJSONObject(i);
String chatid = item.getString("chatid");
String userid = item.getString("userid");
String photo = item.getString("photo");
String nickname = item.getString("nickname");
String fullname = item.getString("fullname");
String sex = item.getString("sex");
String from1 = item.getString("from1");
String from2 = item.getString("from2");
String like = item.getString("like");
String type = item.getString("type");
String content = item.getString("content");
merChatList.add(new Info(total,chatid,userid,photo,nickname,fullname,sex,from1,from2,like,type,content));
}
}
} catch (Exception e) {
Log.d(TAG,"+Exception e "+e);
}
callBack.onDone(merChatList);
}
}.start();
}
------解决思路----------------------
判断是否数据改变 改变了就清理掉重新弄吧 如果没改变就不动了被 因为你网上获取的 哪怕只改变一条也没准是中间的一条被删除了 那怎么办。。。
请问,使用XListView的显示从网络数据库获取的数据。
刚开始调用: updatenetworkdata ()获取网络数据库最新的数据。比如说 第一次调用后merChatList得到的数据是:
a
b
c
那么当下拉屏幕的时候,就会调用 onRefresh() 函数 在次函数里边 再次调用updatenetworkdata ()函数。假设这时候 网络数据库没有更新,那么这时候
merChatList的数据为:
a
b
c
a
b
c
也就是重复了。
本来就想 当下拉更新的时候, //mMemberChatList.clear();
先清除数据,然后获取最新的数据的。
但是这样重新取数据的话,会很费时的。再说 有时候 网数据库只更新了 一条数据,如果把之前删除了,再取就好像
有点不妥。
请会的朋友帮忙回复下,这个应该怎么处理,谢谢啦
public void updatenetworkdata (final String url, final MemberChatCallBack callBack){
new Thread() {
public void run() {
//mMemberChatList.clear();
String objectString = objectToString();
String info = CustomHttpClient.postByHttpClient(objectString);
try {
JSONObject jsonObject = new JSONObject(info);
String total = jsonObject.getString("total");
JSONArray jsonArray = jsonObject.getJSONArray("data");
for( int i=0;i<jsonArray.length();i++ ) {
JSONObject item = jsonArray.getJSONObject(i);
String chatid = item.getString("chatid");
String userid = item.getString("userid");
String photo = item.getString("photo");
String nickname = item.getString("nickname");
String fullname = item.getString("fullname");
String sex = item.getString("sex");
String from1 = item.getString("from1");
String from2 = item.getString("from2");
String like = item.getString("like");
String type = item.getString("type");
String content = item.getString("content");
merChatList.add(new Info(total,chatid,userid,photo,nickname,fullname,sex,from1,from2,like,type,content));
}
}
} catch (Exception e) {
Log.d(TAG,"+Exception e "+e);
}
callBack.onDone(merChatList);
}
}.start();
}
------解决思路----------------------
判断是否数据改变 改变了就清理掉重新弄吧 如果没改变就不动了被 因为你网上获取的 哪怕只改变一条也没准是中间的一条被删除了 那怎么办。。。