How to set text on a single row RecyclerView?

I need to set the text of my single row RecyclerView when button is clicked, who can I achieve that?

This is the adapter:

public class VideoAdapter extends RecyclerView.Adapter<VideoAdapter.VideoHolder> {

    private ArrayList<Video> mData;
    private ArrayList<Video> mData2;
    private Fragment mACtivity;
    private OnImageClickListener onImageClickListener;
    String iddd;
    int id_item;
    ArrayList<Integer> arrayListInteger;
    int c;
    String d = "";
    ArrayList<String> arrayListString;
    int j;
    Context context;
    ArrayList<String> arrayList;

    public VideoAdapter(ArrayList<Video> data, ArrayList<Video> data2, Fragment fragment, OnImageClickListener onImageClickListener, String id, ArrayList<Integer> al,Context mContext) {
        this.mData = data;
        this.mData2 = data2;

        this.mACtivity = fragment;
        this.onImageClickListener = onImageClickListener;

        this.iddd = id;
        this.id_item = id_item;
        this.arrayListInteger = al;
        this.context=mContext;
       // arrayListInteger.clear();
        System.out.println("NO O SI?" + arrayListInteger);
        System.out.println("SI O NO?" + arrayListString);
    }

    @Override
    public VideoHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.anteprima_list_item, parent, false);
        return new VideoHolder(view);
    }

    public interface OnImageClickListener {
        void onImageClick(String imageData);

        void onImageClick2(String imageData);

        void onPreferitiClick2(String imageData, String titolo, String sottotitolo, String data, String id);

        void onTogliPreferitiClick2(String imageData, String id);
        //void aggiungiCommento(String imageData, String id);
    }

    @Override
    public void onBindViewHolder(final VideoHolder holder, final int position) {
        final Video video = mData.get(position);
        final Video video2 = mData2.get(position);
        final int pos=position;
        holder.setTitolo(video.getTitolo());
        holder.setSottoTitolo(video.getSottotitolo());
        holder.setData(video.getData());
        System.out.println("ARRAYLISTINTEGER"+arrayListInteger.size());

        for (int i = 0; i < arrayListInteger.size(); i++) {
            c = arrayListInteger.get(i);
            System.out.println("ARRAYLISTINTEGER"+c);
            if (c == position) {
                System.out.println("POSIZIONE:" + c + "VALORE:" + d);
                System.out.println("INDICE ARRAYLIST:" + c);
                holder.preferiti.setText("togli dai preferiti");
            }
        }

        Glide.with(mACtivity)
                .load(video2.getPic())
                .into(holder.videoImageView);
        holder.linearlayout.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                onImageClickListener.onImageClick(video2.getPic());

            }
        });
        holder.iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onImageClickListener.onImageClick2(video2.getPic());

            }
        });
           /* holder.button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    holder.tt.setText(holder.tw.getText());
                }
            });*/
        arrayList= new ArrayList<String>();
        holder.button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                System.out.println("IDDD:"+iddd);
                System.out.println("IDDD:"+video2.getPic());
                String commento= (holder.tw.getText().toString());
                holder.tw.setText(" ");
                final ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, arrayList);
                arrayList.add(commento);
                holder.lw.setAdapter(adapter);
                System.out.println("LISTVIEW:"+arrayList);
            }
        });

2 answers

  • answered 2018-01-19 12:26 R.Anjali

    Inside onBindViewHolder you can give onClick of button and setText there.

    @Override
        public void onBindViewHolder(final MyViewHolder holder, int position) {
    
          holder.button.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  holder.textview.setText("jjjj");
              }
          });
        }
    

  • answered 2018-01-19 13:57 Vodet

    Inside your onClickListener change it with this

    arraylist.get(0) = "your new string"
    

    then refresh the adapter with

    adapter.notifyDataSetChanged()