我遵循了教程,但是每个教程都有各自的逻辑,我尝试了这段代码,但有一个问题,就是列表没有被新列表替换,而我编写了将搜索结果列表替换为旧列表的代码,请记住我的{{1 }}运作正常,唯一的问题是搜寻检视无法运作
这是我的代码
recycler-view
adapter class
主班
public class AdlistAdapter extends RecyclerView.Adapter<AdlistAdapter.AdViewHolder> {
private Context mCtx;
private List<DetailsofAd> productList;
public AdlistAdapter(Context mCtx, List<DetailsofAd> productList) {
this.mCtx = mCtx;
this.productList = productList;
}
//note my list is perfectly working
//here is filter method
public void setFilter(ArrayList<DetailsofAd> newList){
productList=new ArrayList<>();
productList.addAll(newList);
notifyDataSetChanged();
}
答案 0 :(得分:0)
不要在filter方法中创建新列表。只需通过this.productList进行分配即可。 请以此更改您的代码。
public class AdlistAdapter extends RecyclerView.Adapter<AdlistAdapter.AdViewHolder> {
private Context mCtx;
private List<DetailsofAd> productList;
public AdlistAdapter(Context mCtx, List<DetailsofAd> productList) {
this.mCtx = mCtx;
this.productList = productList;
}
//note my list is perfectly working
//here is filter method
public void setFilter(ArrayList<DetailsofAd> newList){
this.productList = newList;
notifyDataSetChanged();
}