How to create RecyclerView and CardView in Android

  1. First create any class (e.g. with needed fields, set contructor with parameters and set Getters and Setters:

2. Create items.xml file with needed components and cover it with CardView:

3. Create new class;

3.1. Firstly: extends RecyclerView.Adapter<MyAdapter.ViewHolder>;

3.2. Create 2 fields:

Context context;
List<Product>productList = new ArrayList<>();

3.3. Create Constructor with above parameters;

3.4. Create inner class ViewHolder and Find views from items.xml

3.5. Create View object and inflate it

3.6. Bind ViewHolder’s views with the created List field

4. In activity_main.xml create <RecyclerView/> with the id List

5. In class:

5.1. Create field List<Product> productList = new ArrayList<>() and initialize it.

5.2. Find RecyclerView from activity_main.xml

5.3. Create LinearLayoutManager and set it to RecyclerView

5.4. Create MyAdapter object with the parameters this” and created List” and set to RecyclerView

6. Have fun :)

7. GitHub project link