I am currently trying to set an onClickListner to each item of the list in my RecyclerView. I was wondering which method is the best to this and the pros and cons of each.
I found two ways. This one seems more simpler:
They just add it to each item in the onCreateViewHolder()
method
private final OnClickListener mOnClickListener = new MyOnClickListener();
@Override
public MyViewHolder onCreateViewHolder(final ViewGroup parent, final int viewType) {
View view = LayoutInflater.from(mContext).inflate(R.layout.myview, parent, false);
view.setOnClickListener(mOnClickListener);
return new MyViewHolder(view);
}
The method in this article seems more confusing to me which is creating an interface in the adapter class and implementing it in the Activity file:
https://medium.com/androiddevelopers/android-data-binding-recyclerview-db7c40d9f0e4
What would be the benefit of doing it this way?