显示这些项目,直到我在SearchView中键入任何内容,然后这些项目都消失了。
当我键入任何内容时,fullOffers的大小似乎变为零;因为当我将Toast消息放到for循环中时,它不会出现。
我将getFilter方法添加到RecyclerView的适配器中,并将其与fragemnt中的SearchView链接。
public class OffersAdapter extends RecyclerView.Adapter<OffersAdapter.ViewHolder> implements Filterable{
Context context;
List<offer> offers;
List<offer> fullOffers;
public OffersAdapter(List Offers,Context mContext){
context = mContext;
offers = Offers;
fullOffers = new ArrayList<>(Offers);
}
public Filter getFilter() {
return exampleFilter;
}
private Filter exampleFilter = new Filter() {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
ArrayList<offer> filteredList = new ArrayList<>();
if (constraint == null || constraint.length() == 0) {
filteredList.addAll(offers);
} else {
String filterPattern = constraint.toString().toLowerCase().trim();
Toast.makeText(context,"item added",Toast.LENGTH_LONG).show(); // the toast message appears
for (offer item : fullOffers) {
Toast.makeText(context,"item added",Toast.LENGTH_LONG).show(); // it doesn't appear
if (item.getTitle().toLowerCase().contains(filterPattern)) {
filteredList.add(item);
}
}
}
FilterResults results = new FilterResults();
results.values = filteredList;
return results;
}
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
offers.clear();
offers.addAll((List) results.values);
notifyDataSetChanged();
}
};
}
我希望这些物品被加载到“要约”列表中并出现
答案 0 :(得分:0)
尝试更改publishResults方法,如下所示:
$this->session->set_flashdata('pesan','Maaf Username dan Password Salah !');