0

I have my activity_main.xml here :

enter image description here

I use adapter and recycler view to display each item. And this is my activity_list_item.xml:

enter image description here

I want to change/update my note so i need to add setOnClickListener method but i don't know which element that should be clicked. I tried to use setOnClickListener on recycler view but it did not work

Yustina Yasin
  • 147
  • 2
  • 12
  • 3
    you need to set onClick Listener to recycler View items instead of recyclerView itself. Just google it and there are tons of articles and tutorials how to do that. Here is the eg for the same : https://medium.com/android-gate/recyclerview-item-click-listener-the-right-way-daecc838fbb9 – WhiteSpidy. Dec 11 '20 at 06:14
  • 1
    Does this answer your question? [RecyclerView onClick](https://stackoverflow.com/questions/24471109/recyclerview-onclick) – Majid Ali Dec 11 '20 at 06:20
  • @MohammedHanif.thanks, i don't know the right keyword to search – Yustina Yasin Dec 11 '20 at 06:43

1 Answers1

2

in your adapter class you can put viewholder class that implement onClickListener

public class YourClassAdapter extends RecyclerView.Adapter<YourClassAdapter.YourViewHolder> {

    //your code

    class YourViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
       
        TextView price;
    
        public YourViewHolder(@NonNull View itemView) {
            super(itemView);
            //change to your view id
            price = itemView.findViewById(R.id.txtprecio1);
    
            itemView.setOnClickListener(this);
    
        }
    
    
      @Override
          public void onClick(View view) {
           //do something when clicked
       }
    }
}

then put your code you want on function onClick

Mochamad Taufik Hidayat
  • 1,264
  • 3
  • 21
  • 32