如何刷新listview android [英] How to refresh listview android

查看:86
本文介绍了如何刷新listview android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从本地数据库搜索记录到listview但listview不能刷新..



我尝试过:



edSearch.addTextChangedListener(new TextWatcher(){



@Override

public void onTextChanged(CharSequence arg0,int arg1,int arg2,

int arg3){

String sSearch = edSearch.getText()。toString();

SiCommon oDb =新的SiCommon(Constants.PACKEGEDIRECTORYPATH,

Constants.DBNAME);



String sSelectQuery =(SELECT * FROM stud_table WHERE名称喜欢'%'

+ sSearch +%');



Log.e(MAIN ACTIVITY,sSelectQuery );

oDb.getList(sSelectQuery);







}



@Override

public void beforeTextChanged(CharSequence arg0,int arg1,

int arg2,int arg3) {



}



@Override

public void afterTextChanged(可编辑的arg0){



}

});

i am try to search record from local database into listview but listview cant refresh ..

What I have tried:

edSearch.addTextChangedListener(new TextWatcher() {

@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
String sSearch = edSearch.getText().toString();
SiCommon oDb = new SiCommon(Constants.PACKEGEDIRECTORYPATH,
Constants.DBNAME);

String sSelectQuery = ("SELECT * FROM stud_table WHERE Name LIKE '%"
+ sSearch + "%'");

Log.e("MAIN ACTIVITY", sSelectQuery);
oDb.getList(sSelectQuery);



}

@Override
public void beforeTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3) {

}

@Override
public void afterTextChanged(Editable arg0) {

}
});

推荐答案

您正在发送 notifyDataSetChanged 消息,您可以更改数据,因此它将重新显示现有列表。然后发送 notifyDataSetInvalidated ,它告诉适配器数据不再有效,因此忽略了进一步的更改消息。看看 BaseAdapter | Android开发者 [ ^ ]有关详细信息。
You are sending the notifyDataSetChanged message befor you change the data, so it will just redisplay the existing list. You then send notifyDataSetInvalidated which tells the adapter that the data is no longer valid so it ignores further change messages. Take a look at BaseAdapter | Android Developers[^] for further details.


这篇关于如何刷新listview android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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