如何刷新listview android [英] How to refresh 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 thenotifyDataSetChanged
message befor you change the data, so it will just redisplay the existing list. You then sendnotifyDataSetInvalidated
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屋!