--

Showing posts with label RecyclerView. Show all posts
Showing posts with label RecyclerView. Show all posts

Thursday, 8 November 2018

Chapter -2 : Modern Android Architecture ‘Android Jetpack’ - Working with DataBinding


       The Data Binding Library i.e. support library enables us to bind UI components in our layouts to data sources in your app using a declarative format rather than programmatically. In Simple words, Data binding enables a way to combine the UI with business logic allowing the UI values to update automatically without manual intervention.

Benefits

  • Reduces lot of boilerplate code in our business logic while sync up the UI when new data is available. 
  • Making them simpler and easier to maintain. 
  • Improve the app's performance 
  • Help prevent memory leaks and null pointer exceptions.


How to use ?

To get started with DataBinding, open the build.gradle located under app and enable dataBinding under android module. Once enabled, Sync the project



Adding Data Binding element to Layout file


The expression language allows us to write expressions that connect variables to the views in the layout. The next step in converting the layout file to a data binding layout file is to add the data element. To enable DataBinding in a layout, the root element should start with <layout> tag. Along with it, <data> and <variable> tags are used.



<layout> – Indicate the compiler that this layout has data binding in it so generate the binding class for this layout.
<import> – Similar to how we interpret imports in normal classes. Import a class in this layout.
<variable> – similar to how we interpret variables in normal classes. Declare a variable 'name' and it’s type for the layout to use.
<data> – Parent tag for <import> and <variable> tags for the “data” that we are going to bind for this layout.


Access data in layout through Layout Expressions




It’s structured like a normal class where our imports and most of our variables are declared at the top and we use them at the bottom. The user variable declared within data describes a property that may be used within this layout. Also, if you want to use expressions inside your layout, you can call attribute properties using the “@{}" syntax.


Project structure for Binding Data




The Data Binding Library provides classes and methods to easily observe data for changes. You don't have to worry about refreshing the UI when the underlying data source changes. You can make your variables or their properties observable. The library allows you to make objects, fields, or collections observable.

public class User extends BaseObservable {
String username;
String email;
String userImage;
String info;
public ObservableField<Long> numberOfFriends = new ObservableField<>();
public ObservableField<Long> numberOfArticles = new ObservableField<>();
public ObservableField<Long> numberOfFavourite = new ObservableField<>();
public User() {
}
@Bindable
public String getUsername() {
return username; 
}
public void setUsername(String username) {
this.username = username;
notifyPropertyChanged(BR.username);
}
@BindingAdapter({"profileImage"})
public static void loadImage(ImageView view, String imageUrl) {
Glide.with(view.getContext())
.load(imageUrl)
.apply(RequestOptions.circleCropTransform())
.into(view);
}
@Bindable
public String getUserImage() {
return userImage;
}
public void setUserImage(String userImage) {
this.userImage = userImage;
notifyPropertyChanged(BR.userImage);
}
@Bindable
public String getInfo() {
return info;
}
public void setInfo(String info) {
this.info = info;
notifyPropertyChanged(BR.info);
}
public ObservableField<Long> getNumberOfFriends() {
return numberOfFriends;
}
public ObservableField<Long> getNumberOfArticles() {
return numberOfArticles;
}
public ObservableField<Long> getNumberOfFavourite() {
return numberOfFavourite;
}
}
  • To make User pojo class Observable, extend the class from BaseObservable. For demonstration, both Observable and ObservableField are used in the same class.
  • For variables username, email, userImage and info., @Bindable annotation is used and notifyPropertyChanged is called upon setting new data if needed.
  • Variables numberOfArticless, numberOfFriends, numberOfFavourites are declared as ObservableFields.
  • @BindingAdapter is used to bind profileImage to ImageView in order to load the image from URL using Glide library.


Generating binding class

When you set the root tag of your layout to <layout>, a binding class is generated by the Data Binding library. For instance, activity_main.xml will have a binding class called ActivityMainBinding.
Note : This class holds all the bindings from the layout properties to the layout’s views and knows how to assign values for the binding expressions.



If you are using data binding items in a Fragment, ListView, or RecyclerView adapter, use the inflate() methods of the binding classes or the DataBindingUtil class:




In this chapter, we will make a very simple app that loads images in RecyclerView using data binding library.

DataBinding in RecyclerView


Binding a RecyclerView layout is similar to normal binding except few changes in onCreateViewHolder and onBindViewHolder methods. Create layout named article_row_item.xml. This layout contains an ImageView to render the image in RecyclerView. In this layout, data binding is enabled by keeping the root element as <layout>. The Post model in bound to this layout using <variable> tag.



Generating adapter binding class


Create a class named ArticleAdapter.java under view package. As the layout name is article_row_item.xml, the generated binding class will be ArticleRowItemBinding. In onCreateViewHolder() method, article_row_item layout is inflated with the help of ArticleRowItemBinding class. articleViewHolder.rowItemBinding.setArticle() binds the Post model to each row.

public class ArticleAdapter extends RecyclerView.Adapter<ArticleAdapter.ArticleViewHolder> {
private List<Article> articleList;
private LayoutInflater layoutInflater;
private ArticlesAdapterListener listener;
public ArticleAdapter(List<Article> articleList, ArticlesAdapterListener listener) {
this.articleList = articleList;
this.listener = listener;
}
@NonNull
@Override
public ArticleViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
if (null == layoutInflater) {
layoutInflater = LayoutInflater.from(viewGroup.getContext());
}
ArticleRowItemBinding articleRowItemBinding = DataBindingUtil.inflate(layoutInflater, R.layout.article_row_item, viewGroup, false);
return new ArticleViewHolder(articleRowItemBinding);
}
@Override
public void onBindViewHolder(@NonNull ArticleViewHolder articleViewHolder, final int i) {
articleViewHolder.rowItemBinding.setArticle(articleList.get(i));
articleViewHolder.rowItemBinding.thumbnail.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (listener != null) {
listener.onArticleClicked(articleList.get(i));
}
}
});
}
@Override
public int getItemCount() {
return articleList.size();
}
public class ArticleViewHolder extends RecyclerView.ViewHolder {
private ArticleRowItemBinding rowItemBinding;
public ArticleViewHolder(final ArticleRowItemBinding binding) {
super(binding.getRoot());
this.rowItemBinding = binding;
}
}
public interface ArticlesAdapterListener {
void onArticleClicked(Article post);
}
}


Loading RecyclerView in MainActivity


As the main activity layout name is activity_main, the generated binding class will be ActivityMainBinding. loadUserData() renders the user information such as username, , articles, friends and favourite count. init() initialize the RecyclerView with sample images data. AppClickHandlers handles the click events of UI elements. Here, all the binding of click events is done via xml layout only. We don’t explicitly assign anything from activity code.

public class MainActivity extends AppCompatActivity implements ArticleAdapter.ArticlesAdapterListener {
private User user;
private ActivityMainBinding binding;
private AppClickHandlers handler;
private RecyclerView recyclerView;
private ArticleAdapter articleAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
handler = new AppClickHandlers(this);
loadUserData();
init();
}

private void loadUserData() {
user = new User();
user.setUsername("Mr. Sherlock Holmes");
user.setUserImage("https://tse4.mm.bing.net/th?id=OIP.gHhJlg-RAvR-XosdERsIMQHaEo&pid=Api&w=1440&h=900&rs=1&p=0");
// updating ObservableField
user.numberOfArticles.set(1500L);
user.numberOfFriends.set(205090L);
user.numberOfFavourite.set(10L);
// display user
binding.setUser(user);
// assign click handlers
binding.setHandlers(handler);
}
private void init() {
recyclerView = binding.recyclerView;
recyclerView.setLayoutManager(new GridLayoutManager(this, 3));
recyclerView.addItemDecoration(new GridItemDecoration(3, ImageUtil.dpToPx(MainActivity.this, 4), true));
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setNestedScrollingEnabled(false);
articleAdapter = new ArticleAdapter(getArticles(), this);
recyclerView.setAdapter(articleAdapter);
}
private ArrayList<Article> getArticles() {
ArrayList<Article> articles = new ArrayList<>();
for (int i = 1; i < 10; i++) {
Article article = new Article();
article.setImageUrl("https://tse3.mm.bing.net/th?id=OIP.f1bDVK_DN6xiTaYAM79ucgHaEK&pid=Api");
articles.add(article);
}
return articles;
}

@Override
public void onArticleClicked(Article article) {
Toast.makeText(getApplicationContext(), "Article clicked! " + article.getImageUrl(), Toast.LENGTH_SHORT).show();
}

public class AppClickHandlers {
Context context;
public AppClickHandlers(Context context) {
this.context = context;
}
public void onFriendsClicked(View view) {
Toast.makeText(context, "Friends is clicked!", Toast.LENGTH_SHORT).show();
}
public void onFavouriteClicked(View view) {
Toast.makeText(context, "Favourite is clicked!", Toast.LENGTH_SHORT).show();
}
public void onArticlesClicked(View view) {
Toast.makeText(context, "Article is clicked!", Toast.LENGTH_SHORT).show();
}
}
}


Run and test the app once. Make sure the device is having internet connection as images will be downloaded from network.
I have uploaded the latest source code in GitHub for your reference. Kindly raise your queries in the command section.

References :

https://developer.android.com/topic/libraries/data-binding/
https://www.androidhive.info/android-working-with-databinding/
http://imakeanapp.com/android-jetpack-data-binding/

Happy coding!!!
Cheers!!!

Thursday, 9 February 2017

Flexi-RecyclerView

The more advanced and flexible features of Listview is called Recycler View. A large amount of data sets is loaded & scrolled very efficiently by maintaining a limited number of views. I have developed the FelxiRecycler application which loads tourist places in Recycler view customized with CardView widget.
A layout manager positions item views inside a RecyclerView and determines when to reuse item views that are no longer visible to the user. I am loading UI based on user choice either cards or grids.



Step 1: Add required library in gradle
compile 'com.android.support:support-annotations:23.2.0'
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:design:23.2.0'
compile 'com.android.support:cardview-v7:23.2.0'
compile 'com.android.support:recyclerview-v7:23.2.0'
compile 'com.mcxiaoke.volley:library-aar:1.0.1'
Step 2: Designing layout for custom cards
Add RecyclerView to the main layout & designing custom CardView to load show datasets efficiently.
//Initializing ViewsrecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
recyclerView.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
Step 3: Creating & loading data into RecyclerAdapter
We have to create View Holder to fetch UI elements from holder and get data from ArrayList based on position then assign values to UI elements in onBindViewHolder method.
@Overridepublic ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View v = LayoutInflater.from(parent.getContext()).inflate(
            R.layout.tourist_place_list, parent, false);
    v.setOnClickListener(new PlacesOnClickListener());
    ViewHolder viewHolder = new ViewHolder(v);
    return viewHolder;
}
@Overridepublic void onBindViewHolder(ViewHolder holder, int position) {

    TouristPlaceModal place =  touristPlaceList.get(position);

    imageLoader = CustomVolleyRequest.getInstance(context).getImageLoader();
    imageLoader.get(place.imageUrl, ImageLoader.getImageListener(holder.imageViewPlace,
            R.drawable.default_pic, android.R.drawable.ic_dialog_alert));

    holder.imageViewPlace.setImageUrl(place.imageUrl, imageLoader);
    holder.textViewPlaceName.setText(place.name);
    holder.textViewPlaceRank.setText(String.valueOf(place.rank));
    holder.textViewPlaceCity.setText(place.city);
    holder.textViewPlaceBestTime.setText(place.bestTime);
    holder.textViewPlaceHoursSpent.setText(place.hoursSpent+" hours");
}
Step 4:  Creating & loading data into GridAdapter
if (view == null) {
    LayoutInflater inflater = (LayoutInflater) context.getSystemService
            (Context.LAYOUT_INFLATER_SERVICE );
    view = inflater.inflate(R.layout.tourist_place_grid_raw, parent, false);
    gridViewImageHolder = new ViewHolder();
    gridViewImageHolder.imageViewPlace = (NetworkImageView)
            view.findViewById(R.id.networkImgPlace);
    gridViewImageHolder.textViewPlaceName= (TextView)
            view.findViewById(R.id.txtPlaceName);
    gridViewImageHolder.textViewPlaceCity= (TextView)
            view.findViewById(R.id.txtCity);
    view.setTag(gridViewImageHolder);
} else {
    gridViewImageHolder = (ViewHolder) view.getTag();
}
Reinitializing ViewHolder if convertView is null. Loading image url into imageView using Volley imageLoader.
TouristPlaceModal place =  touristPlaceList.get(position);
imageLoader = CustomVolleyRequest.getInstance(context).getImageLoader();
if(place.imageUrl!=null){
    imageLoader.get(place.imageUrl,
            ImageLoader.getImageListener(gridViewImageHolder.imageViewPlace,
            R.drawable.default_pic, android.R.drawable.ic_dialog_alert));
    gridViewImageHolder.imageViewPlace.setImageUrl(place.imageUrl, imageLoader);
}
Step 5: Initializing adapter
//Finally initializing our adapteradapter = new CardviewAdapter(listPlaces,recyclerView, this);
//Adding adapter to recyclerviewrecyclerView.setAdapter(adapter);

adapterGrid=new GridAdapter(listPlaces,this);
gridviewPlaces.setAdapter(adapterGrid);
I have uploaded the complete source code in Github,
https://github.com/JayaprakashR-Zealot/Knowledge-Circle---Android/tree/master/FlexiListview

Happy Coding !!!
Cheers!

Friday, 2 December 2016

Smooth Parallel (i.e. Horizontal) RecyclerView

            If we need to portray complex list with bulk content with slinky animation ( i.e. material design styles) in your apps, the better choice must be the RecyclerView and CardView widgets.

 In this post, we are going to understand the how to populate images in Recycler view through horizontal direction with customized CardView layout. We also learn custom ItemAnimator, onItemClickListener for RecyclerView as well. This application shows a horizontal category RecyclerView that shows the images of shirt, pant, overcoat, hat, and etc. The choices populate based on selected category from Recycler View. You can find the workflow from below video.




If you want to use a RecyclerView, you will need to work with the following:
  • RecyclerView.Adapter - To handle the data collection and bind it to the view
  • LayoutManager - Helps in positioning the items
  • ItemAnimator - Helps with animating the items for common operations such as Addition or Removal of an item. 

        Moreover, the add or remove data in Listview had been extremely difficult to do. RecyclerView is mandatory to implement the ViewHolder Class that was already a recommended practice in Listview but now deeply integrated with this RecyclerView framework. You can find the detailed explanation for RecyclerView components here.

Why RecyclerView than ListView

  • Required ViewHolder in Adapters - ListView adapters do not require the use of the ViewHolder. In contrast, implementing an adapter for RecyclerView requires the use of the ViewHolder pattern for better performance.    
  • Customizable Item Layouts - The RecyclerView has a RecyclerView.LayoutManager that allows any item layouts including horizontal lists or staggered grids.
  • Easy Item Animations - ListView contains no special provisions through which one can animate the addition or deletion of items. In contrast, the RecyclerView has the RecyclerView.ItemAnimator class for handling item animations.
  • Manual Data Source - ListView had adapters for different sources such as ArrayAdapter and CursorAdapter for arrays and database results respectively. In contrast, the RecyclerView.Adapter requires a custom implementation to supply the data to the adapter.
  • Manual Item Decoration - ListView has the android:divider property for easy dividers between items in the list. In contrast, RecyclerView requires the use of a RecyclerView.ItemDecoration object to setup much more manual divider decorations.
  • Manual Click Detection - ListView has a AdapterView.OnItemClickListener interface for binding to the click events for individual items in the list. In contrast, RecyclerView only has support for RecyclerView.OnItemTouchListener which manages individual touch events but has no built-in click handling.

 Components of a RecyclerView

LayoutManager

        A layout manager positions item views inside a RecyclerView and determines when to reuse item views that are no longer visible to the user. To reuse (or recycle) a view, a layout manager may ask the adapter to replace the contents of the view with a different element from the data set. Recycling views in this manner improve performance by avoiding the creation of unnecessary views or performing expensive layout id lookups.

  • LinearLayoutManager - shows items in a vertical or horizontal scrolling list.
  • GridLayoutManager - shows items in a grid.
  • StaggeredGridLayoutManager - shows items in a staggered grid.

RecyclerView.Adapter

         RecyclerView is a similar approach to the ones you already used, but with some peculiarities, such as a required ViewHolder. You will have to override two main methods:
  • onCreateViewHolder() - One to inflate the view and its view holder.
  • onBindViewHolder() - One to bind data to the view. 
The good thing about this is that first method is called only when we really need to create a new view. No need to check if it’s being recycled.

RecyclerView.ItemAnimator

         The add/delete/select operations are notified to the adapter. DefaultItemAnimator can be used for basic default animations and works quite well.

RecyclerView.OnItemClickListener

By implementing the RecyclerView.OnItemTouchListener to respond to only single tap events. This is just a beginning and extended to provide more complex gestures like long click etc.

Workflow for Parallel Recycler View

Now back to our Parallel Recycler View App.

Step 1 : Add recycler view dependency

compile 'com.android.support:cardview-v7:23.1.0'
compile 'com.android.support:recyclerview-v7:23.1.0'

Add these two dependencies in app.gradle

Step 2 : Add recycler view to activity_main.xml layout

<android.support.v7.widget.RecyclerView
    android:id="@+id/category_recycler_view"
    android:layout_width="match_parent"
    android:layout_height="80dp"
    android:layout_below="@+id/imageUser"
    android:scrollbars="none" />

Step 3 : Creating model class

public class Category implements Serializable {

    public String cat_name,cat_description;
    public int cat_id,cat_icon;
}
Serializing a class file provides a fast and efficeint way to store information produced by your application. 

Step 4: Creating Adapter class

      The adapter's role is to convert an object to a position into a list row item to be inserted. However,  with a RecyclerView the adapter requires the existence of a "ViewHolder" object which describes and provides access to all the views within each item row.

public class CategoryAdapter extends RecyclerView.Adapter<CategoryAdapter.AKCViewHolder>{

    private Context mContext;
    private List<Category> mCategoryList;
    private final static int FADE_DURATION = 300; // in milliseconds    private int lastPosition = -1;

    public class AKCViewHolder extends RecyclerView.ViewHolder {
        public ImageView categoryIcon;

        public AKCViewHolder(View view) {
            super(view);
            categoryIcon = (ImageView) view.findViewById(R.id.categoryImage);
        }
    }

    public CategoryAdapter(Context mContext, List<Category> cateList) {
        this.mContext = mContext;
        this.mCategoryList = cateList;
    }

    @Override    public AKCViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View categoryItem= LayoutInflater.from(parent.getContext()).inflate
                (R.layout.list_single_card,parent,false);
        return new AKCViewHolder(categoryItem);
    }

    @Override    public void onBindViewHolder(AKCViewHolder holder, int position) {
        Category categoryItem=mCategoryList.get(position);
        Bitmap icon = BitmapFactory.decodeResource(mContext.getResources(),categoryItem.cat_icon);
        holder.categoryIcon.setImageBitmap(icon);

        // Set the view to scale        //setScaleAnimation(holder.categoryIcon);
        if(CATEGORY_SELECTED_POSITION == position){
            // Here I am just highlighting the background            holder.categoryIcon.setBackgroundColor(mContext.getResources()
                    .getColor(R.color.colorPickedItem));
        }else{
            holder.categoryIcon.setBackgroundColor(mContext.getResources()
                    .getColor(R.color.colorItembg));
        }
    }

    @Override    public int getItemCount() {
        return mCategoryList.size();
    }
} 

Every adapter has three primary methods: onCreateViewHolder to inflate the item layout and create the holder, onBindViewHolder to set the view attributes based on the data and getItemCount to determine the number of items.
With the adapter completed, all that is remaining is to bind the data from the adapter into the RecyclerView.

Step 5 : Adding adapter to RecyclerView

mCategoryList=new ArrayList<>();
mCategoryAdapter=new CategoryAdapter(MainActivity.this,mCategoryList);

mCategoryRecyclerView = (RecyclerView) findViewById(R.id.category_recycler_view);
mCategoryRecyclerView.setAdapter(mCategoryAdapter);
In MainActivity.java binding adapter to RecyclerView.

Step 6: Assigning LayoutManager to RecyclerView

// Enable optimizations if the items are static and will not change for significantly smoother scrollingmCategoryRecyclerView.setHasFixedSize(true);

RecyclerView.LayoutManager mCateLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
mCategoryRecyclerView.setLayoutManager(mCateLayoutManager);

We assign the HORIZONTAL orientation at LinearLayoutManager for RecyclerView. We have to setHasFixedSize(true) by enabling optimizations if the items are static and will not change for significantly smoother scrolling.

Step 7 : Loading data to Category

private void prepareCategory(){
    int[] mAccessoryIcon = new int[]{
            R.drawable.category_shirt,
            R.drawable.category_pant,
            R.drawable.category_overcoat,
            R.drawable.category_gown,
            R.drawable.category_hat,
            R.drawable.category_tie,
            R.drawable.category_bride,
            R.drawable.category_handbag,
            R.drawable.category_tees,
            R.drawable.category_shoe,
            R.drawable.category_cutshoe,
            };
    String[] mAccessoryName=getResources().getStringArray(R.array.accessoryName);

    for (int i=0;i<mAccessoryIcon.length;i++){
        Category category=new Category();
        category.cat_id=i;
        category.cat_name=mAccessoryName[i];
        category.cat_icon=mAccessoryIcon[i];
        category.cat_description=mAccessoryName[i]+" details";
        mCategoryList.add(category);
    }
    mCategoryAdapter.notifyDataSetChanged();
}

Call prepareCategory() in OnCreate() to load data in mCategoryList ArrayList. Finally, compile and run the app and you should see something like the screenshot below. 

Step 7: Creating custom OnItemClickListener

         An important point that the guide leaves out is about handling clicks on the recycler view items. There is no such thing as OnItemClickListener for RecyclerViews. Given that RecyclerView takes ListView a step further and doesn't have a concept of a row/column, but rather an arbitrarily laid out amount of children, they have delegated the onClick to each one of them, or to programmer implementation. So We should implement OnItemTouchListener to achieve this issue.

public class RecyclerItemClickListener implements RecyclerView.OnItemTouchListener  {

    private OnItemClickListener mListener;

    public interface OnItemClickListener {
        public void onItemClick(View view, int position);
    }

    GestureDetector mGestureDetector;

    public RecyclerItemClickListener(Context context, OnItemClickListener listener) {
        mListener = listener;
        mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
            @Override            public boolean onSingleTapUp(MotionEvent e) {
                return true;
            }
        });
    }

    @Override    public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) {
        View childView = view.findChildViewUnder(e.getX(), e.getY());
        if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) {
            mListener.onItemClick(childView, view.getChildAdapterPosition(childView));
        }
        return false;
    }

    @Override    public void onTouchEvent(RecyclerView view, MotionEvent motionEvent) {
    }

    @Override    public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {

    }
} 

Step 8: Implementing addOnItemTouchListener

mCategoryRecyclerView.addOnItemTouchListener(
        new RecyclerItemClickListener(MainActivity.this, new RecyclerItemClickListener.
          OnItemClickListener() {
            @Override            public void onItemClick(View view, int position) {

                // Updating old as well as new positions 
               mCategoryAdapter.notifyItemChanged(CATEGORY_SELECTED_POSITION);
                CATEGORY_SELECTED_POSITION = position;
                mCategoryAdapter.notifyItemChanged(CATEGORY_SELECTED_POSITION);

                Category category=mCategoryList.get(position);
                Toast.makeText(view.getContext(),"Category : "+
            category.cat_name,Toast.LENGTH_SHORT).show();
                // Load date in choice recyclerview                 
                pickChoice(position);
            }
        }));


By adding addOnItemTouchListener(), we can implement onItemClick in RecyclerView.


I have uploaded the full source code in GitHub,

Happy coding,
Cheers!!!