Handle click item in Recycleview

后端 未结 5 1811
不知归路
不知归路 2021-01-07 08:52

I have a horizontal recycleview inside vertical recycleview.

and i add list cardview inside horizontal rec

5条回答
  •  走了就别回头了
    2021-01-07 09:01

    It would be better to implement OnClickListener on your ViewHolder class and add the listener to your desired views.

    Just in onBindViewHolder(...) add setOnClickListener(...) like this:

    @Override
    public void onBindViewHolder(WordViewHolder holder, final int position) {
    
        //... 
    
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(v.getContext(), position + "", Toast.LENGTH_SHORT).show();
            }
        });
    }
    

提交回复
热议问题