Simplifying RecyclerView step by step

1- Put <RecyclerView/> in xml you want

2- Make resource file // put design for item

No alt text provided for this image

3- Create class that contained data you want in every item in recycler view

No alt text provided for this image

4- Make Recycler Adapter class to link (RecyclerView with arrayList in main activity)

-then define array List of type Item. " item" :is the class we did

-and generate constructor “ constructor mission is to pass arrayList to RecyclerAdapter object in main method as argument”

No alt text provided for this image

5- Make view Holder class inside adapter class

-define variable for every element in resoursefile.xml

-generate constructor to find every element by ID from resoursefile.xml

No alt text provided for this image

6- inside Recycler Adapter class .OnCreateHolderMethod this method mission to inflate adapter with resource file.xml

No alt text provided for this image

7- inside Recycler Adapter class .OnBindViewHolderMethod….make variable to store data selected from list then pass this variable to TextView or ImageView …etc. from Holder class “that pass data in the class into resource file

No alt text provided for this image

8- inside Recycler Adapter class .GetItemcountMethod “put list size into it

No alt text provided for this image

In Main Activity

1-define array List

-add what you want to array list

2-then define recycler View // outside oncreate method then inside oncreate Method and find it by id

3-set Adapter

-make object from adapter class then pass array list to it as argument

-Make recyclerView.layoutManager to define orientation

- setlayoutManager

- setItemAnimater

- setAdapter

Ex:

No alt text provided for this image

要查看或添加评论,请登录

Ahmed Farouk的更多文章

  • MVVM pattern

    MVVM pattern

    ???? ??? MVVM ? ??? ????? ?? ??? patterns! MVVM : Model View View Model ???????? ????? ??? ?? ??? ???? application ??…

  • MVC pattern

    MVC pattern

    MVC in this pattern The activity doing everything Model : the place that will get the data from it View : XML…

社区洞察

其他会员也浏览了