Why does OnClickListener on a ViewHolder don't work?

前端 未结 3 1528
孤街浪徒
孤街浪徒 2020-11-30 06:36

I\'m trying to implement a way to handle item selection on a RecyclerView. I personally don\'t like the way suggested in some answers on SO of passing through g

3条回答
  •  悲哀的现实
    2020-11-30 07:04

    Simplely Click Handler your ViewHolder. Recycler View don't have special attaching click handlers like ListView which has the method setOnItemClickListener().

    ** public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener

    ** in public ViewHolder(Context context, View itemView) set public void onClick(View view)

    ** get position by: int position = getLayoutPosition(); User user = users.get(position);

提交回复
热议问题