I am working on an Ecommerce app and need to make filter and populate RecycleView following is my code for RecycleViewAdapter class:
public class RecyclerViewAdapter
extends RecyclerView.Adapter<RecyclerViewAdapter.MyViewHolder>
implements Filterable {
private static final String TAG = "RecyclerViewAdapter";
private ArrayList<Product> productArrayList;
final private ArrayList<Product> productArrayListFull;
private Context mContext;
public RecyclerViewAdapter(Context context, ArrayList<Product> products){
this.productArrayList = products;
this.mContext = context;
this.productArrayListFull = productArrayList.clone();
}
}
productArrayListFull is just assigned and used to get access to all products but never modified productArrayList is modified based on filters
I have refferd to this for creating RecyclerView - Recycler View and this for creating the filters Filter
Whereas the filtering code resets the productArrayListFull to the filtered results
I have changed the function and decided to manually add products using for loop and added logs for size of the ArrayList and in the logs show 0 for ArrayFullList
public class RecyclerViewAdapter
extends RecyclerView.Adapter<RecyclerViewAdapter.MyViewHolder>
implements Filterable {
private static final String TAG = "RecyclerViewAdapter";
private ArrayList<Product> productArrayList;
private ArrayList<Product> productArrayListFull;
private Context mContext;
public RecyclerViewAdapter(Context context, ArrayList<Product> products){
this.productArrayList = products;
this.mContext = context;
this.productArrayListFull = new ArrayList<>(products);
for (Product p : products)
{
productArrayListFull.add(p);
}
Log.v(TAG,"productArrayList Size" + productArrayList.size());
Log.v(TAG,"productArrayListFull Size" + productArrayListFull.size());
}