send data from recyclerview adapter to main activity

Solutions on MaxInterview for send data from recyclerview adapter to main activity by the best coders in the world

showing results for - "send data from recyclerview adapter to main activity"
Josefa
28 Sep 2018
1public interface OnImageClickListener {
2    void onImageClick(String imageData);
3}
4MainActivity:
5
6public class MainActivity implements OnImageClickListener {
7    @Override
8    public void onImageClick(String imageData) {
9        // handle image data
10    }
11//...
12}
13Your VideoAdapter:
14
15    //...
16    private OnImageClickListener onImageClickListener;
17
18    public VideoAdapter(ArrayList<Video> data, ArrayList<Video> data2, Activity activity, OnImageClickListener onImageClickListener) {
19        this.mData = data;
20        this.mData2 = data2;
21        this.mACtivity = activity;
22        this.onImageClickListener = onImageClickListener;
23    }
24    //...
25    @Override
26    public void onBindViewHolder(VideoHolder holder, int position) {
27        //...
28        holder.restaurantImageView.setOnClickListener(new View.OnClickListener() {
29            @Override
30            public void onClick(View v) {
31                onImageClickListener.onImageClick(video2.getPic());
32            }
33        });
34        //...
35    }
36    //...