如何在单行RecyclerView上设置文本?

时间:2018-01-19 11:07:13

标签: java android android-recyclerview adapter

点击按钮时,我需要设置单行RecyclerView的文本,我可以实现这一目标吗?

这是适配器:

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 个答案:

答案 0 :(得分:0)

在onBindViewHolder中,您可以在那里提供onClick按钮和setText。

@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");
          }
      });
    }

答案 1 :(得分:0)

在onClickListener中,用

更改它
arraylist.get(0) = "your new string"

然后用

刷新适配器
adapter.notifyDataSetChanged()