Well after reading many questions i was disappointed to find out that firebase doesn't implement sqlite “like” query, so i decided to work around it.
I know this question is old, but in case anyone still struggling with finding an answer to this problem, I have found an alternative solution, a work around to be more precise.
when the application start, store the list in memory and keep it as a raw data to query from it everytime you need it, the list will still be synchronized with firebase..here is how i did it.
mRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//Loading data from firebase to the temporary listItem data
ArrayList<ListItem> data = new ArrayList<>();
for(DataSnapshot customList : dataSnapshot.getChildren()){
ListItem item = customList.getValue(ListItem.class);
data.add(item);
}
listData.clear();
listData.addAll(data);
//listData above is my list that i use and re-use (clear and refull, rawListData is like my offline firebase database)
rawListData = new ArrayList<>();
rawListData.addAll(data);
if(firstRun){
firstRun=false;
myAdapter = new MyAdapter(MainActivity.this, listData);
recView.setAdapter(myAdapter);
if(!isBind){
runService();
}
}else{
myAdapter.notifyDataSetChanged();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(MainActivity.this, "Database loading error", Toast.LENGTH_SHORT).show();
}
});
let's say I want to search in my data about a title that contains the word "blues" in it..i just call this thread > filterMusicType("blues");
public void filterMusicType(String type){
//Notify RecyclerView that listData was cleared.
int currentSize = listData.size();
listData.clear();
myAdapter.notifyItemRangeRemoved(0, currentSize);
//Filter data based on music type
for(ListItem item : rawListData){
String station = item.getTitle().toLowerCase();
if(station.contains(type)){
listData.add(item);
}
}
//Notify RecyclerView that listData was laoded with new Data.
myAdapter.notifyItemRangeInserted(0, listData.size());
myAdapter.notifyDataSetChanged();
}