<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Bolu Okunaiya on Medium]]></title>
        <description><![CDATA[Stories by Bolu Okunaiya on Medium]]></description>
        <link>https://medium.com/@boluokunaiya?source=rss-48280df10098------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*K4m27GuDOVlzPs-kXDzPAw.jpeg</url>
            <title>Stories by Bolu Okunaiya on Medium</title>
            <link>https://medium.com/@boluokunaiya?source=rss-48280df10098------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 09:22:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@boluokunaiya/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Evolution of RecyclerView]]></title>
            <link>https://medium.com/@boluokunaiya/evolution-of-recyclerview-7a209b9eece8?source=rss-48280df10098------2</link>
            <guid isPermaLink="false">https://medium.com/p/7a209b9eece8</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Bolu Okunaiya]]></dc:creator>
            <pubDate>Wed, 14 Aug 2019 17:26:06 GMT</pubDate>
            <atom:updated>2019-08-14T17:26:06.341Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve been developing android apps for about 2 years now, i started out using Java but now i use Kotlin and if you are not on that already i’ll advise you do that ASAP! Anyway back to the point of this article, from my experience most android apps consist of RecyclerView mainly , i bet you’ll never build a real world application without using this two multiple times. Initially when i first started of i shied away from this because of the cost it took to implement it but now i do that in about 5 lines of code which i am going to show you and for the sake of new developers i&#39;ll go ahead and tell you what these two are.</p><h3><strong>What is a Recycler View</strong></h3><p>A RecyclerView is used when you have to repeat views so basically the home page on Twitter where you see your tweets is a RecyclerView, your list of friends on Snapchat? Recycler View. Even your list of stories on Medium if you happen to be using the mobile app is a Recycler view so you see i’m not over exaggerating when i say all apps are made multiple of recycler views.</p><p>So how does one use a RecyclerView? 2 years-ago me asked and this is what i found out:</p><p>You need 3 basic things if you are to create a RecyclerView:</p><ol><li><strong>Model: </strong>This is the data that is going to be represented by the Recycler and it&#39;s usually a list of elements, say a list of banks if i&#39;m trying to display a bank list or a list of friends if i&#39;m trying to display my friends list.</li><li><strong>Layout:</strong> This is the layout that basically describes what a single element of the RecyclerView will look like and this is the layout that will be repeated over and over again .</li><li><strong>Adaptor:</strong> An adaptor is like the middle man if i may say, it basically tells the RecyclerView how the data in the model is to be displayed on the layout.</li></ol><h3><strong>Implementing a RecyclerView</strong></h3><p>So lets say we are trying to implement a recycler to display a list of people . This is how it will go:</p><ol><li><strong>Model:</strong></li></ol><pre>public class Person  {<br>    private String name;<br>    private String age;<br><br>    public Person(String name, String age) {<br>        this.name = name;<br>        this.age = age;<br>    }<br><br>    public String getName() {<br>        return name;<br>    }<br><br>    public void setName(String name) {<br>        this.name = name;<br>    }<br><br>    public String getResponseMessage() {<br>        return name;<br>    }<br><br>    public void setResponseMessage(String responseMessage) {<br>        this.name = responseMessage;<br>    }<br>}</pre><p><strong>2. Layout:</strong></p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;<br>    xmlns:tools=&quot;http://schemas.android.com/tools&quot;<br>    android:id=&quot;@+id/root&quot;<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;wrap_content&quot;<br>    android:background=&quot;@drawable/rubixboxitem&quot;&gt;<br><br>    &lt;de.hdodenhof.circleimageview.CircleImageView<br>        android:id=&quot;@+id/circleImageViewPerson&quot;<br>        android:layout_width=&quot;40dp&quot;<br>        android:layout_height=&quot;40dp&quot;<br>        android:layout_marginBottom=&quot;8dp&quot;<br>        android:layout_marginStart=&quot;16dp&quot;<br>        android:layout_marginTop=&quot;8dp&quot;<br>        android:src=&quot;#1976D2&quot;<br>        app:layout_constraintBottom_toBottomOf=&quot;parent&quot;<br>        app:layout_constraintStart_toStartOf=&quot;parent&quot;<br>        app:layout_constraintTop_toTopOf=&quot;parent&quot; /&gt;<br><br>    &lt;TextView<br>        android:id=&quot;@+id/textViewInitial&quot;<br>        android:layout_width=&quot;wrap_content&quot;<br>        android:layout_height=&quot;wrap_content&quot;<br>        android:fontFamily=&quot;@font/buenosaires2web_bold&quot;<br>        android:text=&quot;BO&quot;<br>        android:textColor=&quot;@color/white&quot;<br>        android:textSize=&quot;18sp&quot;<br>        app:layout_constraintBottom_toBottomOf=&quot;@id/circleImageViewAirtime&quot;<br>        app:layout_constraintEnd_toEndOf=&quot;@+id/circleImageViewAirtime&quot;<br>        app:layout_constraintStart_toStartOf=&quot;@+id/circleImageViewAirtime&quot;<br>        app:layout_constraintTop_toTopOf=&quot;@+id/circleImageViewAirtime&quot; /&gt;<br><br><br>    &lt;TextView<br>        android:id=&quot;@+id/textViewHeader&quot;<br>        android:layout_width=&quot;0dp&quot;<br>        android:layout_height=&quot;wrap_content&quot;<br>        android:layout_marginStart=&quot;16dp&quot;<br>        android:ellipsize=&quot;end&quot;<br><br>        android:fontFamily=&quot;@font/buenosaires2web_bold&quot;<br>        android:maxLines=&quot;1&quot;<br>        android:text=&quot;Bolu&quot;<br>        android:textColor=&quot;@color/black&quot;<br>        android:textSize=&quot;14sp&quot;<br>        app:layout_constraintStart_toEndOf=&quot;@+id/circleImageViewAirtime&quot;<br>        app:layout_constraintTop_toTopOf=&quot;@+id/circleImageViewAirtime&quot; /&gt;<br><br><br>    &lt;TextView<br>        android:id=&quot;@+id/textViewContent&quot;<br>        android:layout_width=&quot;0dp&quot;<br>        android:layout_height=&quot;17dp&quot;<br>        android:layout_marginBottom=&quot;8dp&quot;<br>        android:ellipsize=&quot;end&quot;<br>        android:fontFamily=&quot;@font/buenosairesweb_light&quot;<br>        android:maxLines=&quot;1&quot;<br>        android:text=&quot;11&quot;<br>        android:textColor=&quot;#777E8E&quot;<br>        android:textSize=&quot;12sp&quot;<br>        app:layout_constraintBottom_toBottomOf=&quot;parent&quot;<br>        app:layout_constraintStart_toStartOf=&quot;@+id/textViewHeader&quot;<br>        app:layout_constraintTop_toBottomOf=&quot;@+id/textViewHeader&quot; /&gt;<br><br>    &lt;View<br>        style=&quot;@style/Divider3&quot;<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;1dp&quot;<br>        app:layout_constraintBottom_toBottomOf=&quot;parent&quot;<br>        app:layout_constraintEnd_toEndOf=&quot;parent&quot;<br>        app:layout_constraintStart_toStartOf=&quot;parent&quot; /&gt;<br><br>    &lt;!--&lt;ImageView--&gt;<br>        &lt;!--android:id=&quot;@+id/imageView79&quot;--&gt;<br>        &lt;!--android:layout_width=&quot;8dp&quot;--&gt;<br>        &lt;!--android:layout_height=&quot;0dp&quot;--&gt;<br>        &lt;!--android:layout_marginEnd=&quot;8dp&quot;--&gt;<br>        &lt;!--android:layout_marginTop=&quot;4dp&quot;--&gt;<br>        &lt;!--android:layout_marginBottom=&quot;4dp&quot;--&gt;<br>        &lt;!--app:layout_constraintBottom_toBottomOf=&quot;@+id/textViewTime&quot;--&gt;<br>        &lt;!--app:layout_constraintEnd_toStartOf=&quot;@+id/textViewTime&quot;--&gt;<br>        &lt;!--app:layout_constraintTop_toTopOf=&quot;@+id/textViewTime&quot;--&gt;<br>        &lt;!--app:srcCompat=&quot;@drawable/greendot&quot; /&gt;--&gt;<br><br>&lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wes1qO72KHy7Of6S4dPQzw.png" /></figure><p><strong>3. Adaptor: </strong>Now let&#39;s take a deep breath with the adaptor. To use the adaptor there are three main method you should take note of :</p><p>a. onCreateViewHolder : This is where the layout you created goes. Let&#39;s say the name you called it was item_person it will look something like this:</p><pre>public PersonViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {<br>    View itemView = LayoutInflater.<em>from</em>(viewGroup.getContext())<br>            .inflate(R.layout.item_person, viewGroup, false);<br><br>    return new PersonViewHolder(itemView);<br>}</pre><p>b. getItemCount : You tell the adaptor the number of elements you are working with here :</p><pre>public int getItemCount() {<br>    return personList.size();<br>}</pre><p>c. onBindViewHolder : Here you tell the adaptor how an item of the the person list will be displayed in the item_person layout.</p><pre>public void onBindViewHolder(@NonNull PersonViewHolder personViewHolder, int i) {</pre><pre>    Person person = this.personlist.get(i);<br>    personViewHolder.textViewPersonName.setText(person.getName);<br>    personViewHolder.textViewPersonAge.setText(person.getAge);<br><br>    }</pre><p>I bet you see why i shied away from this initially now.</p><h3><strong>Implementing RecyclerView Version 2</strong></h3><p>I found a library on github called <a href="https://github.com/gurleensethi/LiteUtilities">LiteUtilities</a> that reduced the cost of implementing a RecyclerView to this:</p><pre>private void updateRecycler(List&lt;Person&gt; personlist) {<br>        LinearLayoutManager layoutManager<br>  = new LinearLayoutManager(getContext(), RecyclerView.<em>VERTICAL</em>, false);<br>        recyclerView.setLayoutManager(layoutManager);<br>        RecyclerAdapterUtil&lt;Person&gt; recyclerAdapterUtil = new RecyclerAdapterUtil&lt;Person&gt;(getContext(), personlist, R.layout.<em>item_person</em>);<br>        recyclerAdapterUtil.addViewsList(R.id.<em>textViewPersonName</em>,R.id.<em>textViewPersoAge</em>);<br>        recyclerAdapterUtil.addOnDataBindListener(new Function4&lt;View, Person, Integer, Map&lt;Integer, ? extends View&gt;, Unit&gt;() {<br>            @Override<br>            public Unit invoke(View view, Person person, Integer integer, Map&lt;Integer, ? extends View&gt; integerMap) {<br>                TextView tvName = (TextView) integerMap.get(R.id.<em>textViewPersonName</em>);</pre><pre>TextView tvAge = (TextView) integerMap.get(R.id.<em>textViewPersoAge</em>);</pre><pre>tvName.setText(person.getName)<br>tvAge.setText(person.getAge)                <br>                return null;<br>            }<br>        });<br><br>       <br><br>        recyclerView.setAdapter(recyclerAdapterUtil);<br>    }<br><br>}</pre><h3>Implementing RecyclerView Version 3</h3><p>Well now that i’ve switched to Kotlin i created an extension function on the RecyclerView class.</p><pre>fun &lt;T : Any&gt; RecyclerView.updateRecycler(context: Context,listOfItems:List&lt;T&gt;,layout:Int,listOfLayout:List&lt;Int&gt;,binder: (Map&lt;Int, View&gt;,Int) -&gt; Unit) {<br>    this.<em>layoutManager </em>= LinearLayoutManager(context)<br>    val recyclerAdaptor = RecyclerAdapterUtil(context,listOfItems,layout)<br>    recyclerAdaptor.<em>apply </em><strong>{<br>        </strong>addViewsList(listOfLayout)<br>        addOnDataBindListener <strong>{ </strong>itemView, item, position, innerViews <strong>-&gt;   </strong>binder(innerViews,position) <strong>}<br>    }<br>    </strong>this.<em>adapter </em>= recyclerAdaptor<br>}</pre><p>So this is how i implement a RecyclerView now :</p><pre>personRecycler.updateRecycler(<em>context</em>!!,listOfPeople,R.layout.item_person,listOfLayoutItems) <strong>{ </strong>innerViews, position <strong>-&gt;<br>    </strong>val tvName = innerViews[R.id.textViewPersonName] as TextView<br>    val tvAge = innerViews[R.id.textViewPersonAge] as TextView<br>    tvName = listOfPeople[position].getPersonName()<br>    tvAge = listOfPeople[position].getPersonAge()<br><strong>}</strong></pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7a209b9eece8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>