I have implemented SearchView
Widget in my app. Its working fine. Now i need to do is, whenever i type a word in my SearchView Bar
You Should do this in onBindViewHolder() method (using RecyclerView)
class YourAdapter
String searchString="";
@Override
public void onBindViewHolder(AllMessageAdapter.DataObjectHolder holder, final int position) {
holder.message.setText(mDataset.get(position).Message);
AllMessageList.Message message=mDataset.get(position);
String name = message.Message.toLowerCase(Locale.getDefault());
if (name.contains(searchString)) {
int startPos = name.indexOf(searchString);
int endPos = startPos + searchString.length();
Spannable spanString = Spannable.Factory.getInstance().newSpannable(holder.message.getText());
spanString.setSpan(new ForegroundColorSpan(Color.RED), startPos, endPos, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
holder.message.setText(spanString);
}
}
Your Filter(in Adapter)
public void setFilter(ArrayList countryModels,String searchString) {
this.searchString=searchString;
mDataset = new ArrayList<>();
mDataset.addAll(countryModels);
notifyDataSetChanged();
}