0

I have made a RecyclerView with 1 ImageView and 2 TextViews. Now, I want an element to be appended to the RecyclerView (prefereably to the end of the RView), when the element is clicked.

I tried to set the the onClickListener in the onBindViewHolder like this:

@Override
public void onBindViewHolder(final MyViewHolder viewHolder, final int position) {
    viewHolder.text.setText(data.get(position).name);
    viewHolder.dep.setText(data.get(position).dep);
    viewHolder.icon.setImageResource(data.get(position).picid);
    viewHolder.linearLayout.setOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View v) {
            Toast.makeText(context,"Data is copied to the dataset",Toast.LENGTH_LONG).show();
            Datasource ik = new Datasource();
            ik.name = data.get(position).name;
            ik.dep = data.get(position).dep;
            ik.picid = data.get(position).picid;
            data.add();
        }
    });

}

So I don't know what to write to data.add() in the end of the code to actually append the clicked element to my RecyclerView. Can somebody help?

Tried a several variations, but the program either died when an element was clicked, or did nothing.

hotigeftas
  • 151
  • 1
  • 3
  • 9

0 Answers0