Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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) {

}
});
Posted
Comments
Richard MacCutchan 11-Feb-16 4:37am    
Where is the code to refresh the ListView? The simplest way would be to delete the existing ListView and recreate with the new information.
Member 11689187 11-Feb-16 7:34am    
adapter = new ListAdapter(this,R.layout.list_data, studentArrayList);
studentListview.setAdapter(adapter);
studentListview.setTextFilterEnabled(true);



public void onTextChanged(CharSequence s, int arg1, int arg2,int arg3) {

adapter.notifyDataSetChanged();
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);


studentArrayList.clear();
adapter.notifyDataSetInvalidated();
}


1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900