I am a novice! user, I am trying to filter my data using Search View. Filtering seems to work, but when I delete the text in search view to type another, I have only the found item and not my initial list.
More analytically I use the following in the adapter:
public void filterData(String query){
query = query.toLowerCase();
if(query.isEmpty()){
expListTitle .addAll(InitialList);
}
else {
expListTitle.clear();
for(String titles: NewexpListTitle)
{
if(titles.toLowerCase().contains(query))
{
expListTitle.add(titles);
}
}
}
notifyDataSetChanged();
}
and in the constructor of adapter I do the following:
public CustomExpandableListAdapter(Context context, List<String> expListTitle, LinkedHashMap<String,ArrayList<Business>> expListDetail)
{
this.context = context;
this.expListTitle = expListTitle;
this.expListDetail = expListDetail;
this.NewexpListTitle= new ArrayList<String>();
this.NewexpListTitle.addAll(expListTitle);
this.InitialList = new ArrayList<String>();
this.InitialList.addAll(expListTitle);
}
And on my class I gave the following which call FilterData method
@Override
public boolean onQueryTextChange(String query) {
listAdapter = new CustomExpandableListAdapter(getApplicationContext(), FinalListTitle, FinalMap);
listAdapter.filterData(query);
expandableListView.setAdapter(listAdapter);
return false;
}
I have above the setAdapter and initialization because data are coming from JSON object using volley
It seems that when I am clearing the SearchView the list InitialList is cleared as well and its left with the found element . How to keep my initial list in the meanwhile?
Thank you