如何将List从Recylerview传递给Class

时间:2016-11-03 11:47:17

标签: android arraylist interface

我想把Reylerview中的arraylist传递到课堂上,我怎么能实现它?

这是我的自定义过滤器类

@Override
protected FilterResults performFiltering(CharSequence constraint) {

    FilterResults filterResults=new FilterResults();
    if(constraint!=null && constraint.length()>0){
        constraint=constraint.toString().toUpperCase();
         filterArrayList=new ArrayList<>();
        for(int i=0;i<arrayList.size();i++){
            if(arrayList.get(i).getId().toUpperCase().contains(constraint)){
                filterArrayList.add(arrayList.get(i));
            }
        }

        filterResults.count=filterArrayList.size();
        filterResults.values=filterArrayList;
    }else{

        filterResults.count= arrayList.size();
        filterResults.values=arrayList;
    }
    return filterResults;
}

@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
    //Here i want the arraylist from the recylerview without making the arraylist static
    // adapter.items= (List<OrderPogo>) results.values;
    adapter.notifyDataSetChanged();
}

1 个答案:

答案 0 :(得分:0)

实际上你应该在performFiltering方法上获取arrayList。过滤列表后,最后可以编写

filterResults.values = yourList;
filterResults.count = yourList.size();

然后

return filterResults

您将通过

获取publishResults方法的过滤结果列表
result.values

在Filter类中访问arrayList的最佳方法是在RecycleView中创建Filter类。