我在我的app中使用了#!/bin/bash
filename=textFileName
while read -r line
do
python x.py $line >>log.txt
done < "$filename"
和自定义适配器...适配器实现了Filterable for search。如何设置高光搜索文本?
这是我在自定义适配器中可过滤的代码:
RecyclerView
这是我在文本更改活动中的代码(EditText):
private Filter filterResult = new Filter() {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults filterResults = new FilterResults();
ArrayList<Moment> tempList = new ArrayList<>();
if (MOMENT_FILTER != null) {
if (TextUtils.isEmpty(constraint)) {
tempList = (ArrayList<Moment>) MOMENT_FILTER;
} else {
int length = MOMENT_LIST.size();
int i = 0;
while (i < length) {
Moment item = MOMENT_FILTER.get(i);
if (item.getMoment().contains(constraint))
tempList.add(item);
i++;
}
}
}
filterResults.values = tempList;
filterResults.count = tempList.size();
return filterResults;
}
@SuppressWarnings("unchecked")
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
MOMENT_LIST = (ArrayList<Moment>) results.values;
if (results.count > 0) {
notifyDataSetChanged();
}
}
};
@Override
public Filter getFilter() {
return filterResult;
}
答案 0 :(得分:2)
在适配器中引用searchText 然后在你的OnBindViewHolder中你可以做
String text = list.get(position).getText(); // Your getter Method
String htmlText = text.replace(searchText,"<font color='#c5c5c5'>"+searchText+"</font>");
// Only searchText would be displayed in a different color.
holder.textView.setText(Html.fromHtml(htmlText );