如题所述,最好不要每次都new一个listener
业精于勤,荒于嬉;行成于思,毁于随。
Get the component in ViewHolder and set up the monitoring
class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{ public TestHolder(View view){ super(view); view.setOnClickListener(this); View button = view.findViewById(R.id.recycler_item_button); button.setOnClickListener(this); } @Override public void onClick(View v) { if(v.getId() == R.id.recycler_item_button){ Toast.makeText(context,"button"+getAdapterPosition(),Toast.LENGTH_SHORT).show(); }else{ Toast.makeText(context,"item"+getAdapterPosition(),Toast.LENGTH_SHORT).show(); } } }
Set an onclicklistener for the layout of the item's view in the adapter's onbindviewholder, and set a listener for the Button
Recommend https://github.com/CymChad/Ba...
Get the component in ViewHolder and set up the monitoring
Set an onclicklistener for the layout of the item's view in the adapter's onbindviewholder, and set a listener for the Button
Recommend https://github.com/CymChad/Ba...