Android Recyclerview Example

Posted on 10 views
Android RecyclerView is used to produce advance lists as well as cards or grids amongst CardView widgets tin hold upward used together. The RecyclerView is a advanced as well as flexible version of listing view. By using RecyclerView as well as CardView widgets you lot tin brand to a greater extent than cloth blueprint agency app. If you lot desire to add together ListView or GridView within NestedScrollView blueprint back upward library, you lot may appear upward many problems. So if you lot desire to add together lists, cards, grids amongst cloth header view, coordinator layout, I recommend you lot to purpose RecyclerView. You tin customize your cards, lists inwards your ain ways.

In this tutorial, you lot volition acquire to display grids special inwards your android application amongst ikon as well as text using android RecyclerView. For that you lot require to produce coffee file similar DataAdapter, AndroidVersion as well as ItemClickListener.

Related:
Android Material Design GridView Tutorial
Android Fragments Tutorial amongst Example
Start New Activity from Android ListView onItemClick

Android Example: Custom Grid RecyclerView amongst Images as well as Text

Let’s foremost past times creating novel android projection called Android RecyclerView Example. After creating novel projection opened upward build.gradle file as well as add together compile com.android.support:recyclerview-v7:23.2.0 as well as compile com.android.support:design:23.0.0 dependencies. Bulid.gradle file volition await similar below.

build.gradle

 Android RecyclerView is used to produce advance lists as well as cards or grids amongst  Android RecyclerView Example

XML Layout File

Open your primary XML layout file as well as add together android.support.v7.widget.RecyclerView within android.support.design.widget.CoordinatorLayout with id. This volition await similar below.

res/layout/activity_main.xml

Now you lot require to produce a novel XML layout file for grids or lists item. Create row_layout.xml file inwards res/layout as well as add together ImageView as well as TextView within LinearLayout or RelativeLayout amongst unlike id. Following is the consummate content of row_layout.xml file.

res/layout/row_layout.xml

Java Activity File

Open primary coffee activeness file as well as add together next code. Here I convey added text for grid title, images for grid items. Create ArrayList as well as add together onItemTouchListener as well as onItemClickListener inwards recycler view. Following is the consummate code of coffee activeness file.

src/MainActivity.java

Again produce a novel coffee file called AndroidDataAdapter as well as extend into RecyclerView.Adapter<AndroidDataAdapter.ViewHolder>. Defile somebody variable from ArrayList as well as Context. In ViewHolder cast you lot require to connect to grid row layout ikon as well as text similar below. Following is the consummate code of AndroidDataAdapter.java file.

src/AndroidDataAdapter.java

Again, produce a novel coffee file AndroidVersion.java as well as add together next code.

src/ AndroidVersion.java

Handle RecyclerView Item Click Event

Finally, produce a novel coffee file called RecyclerItemClickListener.java to produce recycler special click listener as well as implements it to RecyclerView.OnItemTouchListener. Defile somebody variable to RecyclerView.OnItemTouchListener as well as add together the next code. We convey already added toast message when android recyclerView special click inwards mRecyclerView.addOnItemTouchListener of MainActivity.java file. Following is the consummate coffee code of RecyclerItemClickListener.java file.

src/RecyclerItemClickListener.java

Run your Android RecyclerView Example application which volition await similar higher upward screenshot. If you lot click grid items, a toast message volition appear amongst grid position