recycler adapter class android java

Solutions on MaxInterview for recycler adapter class android java by the best coders in the world

showing results for - "recycler adapter class android java"
Ayanna
08 Aug 2018
1//java,recycler adapter class,Android studio,2021/09/23
2//this is example only. copy,paste,change and use it 
3
4public class RecyclerAdapterClass extends RecyclerView.Adapter<RecyclerAdapterClass.MyViewHolder> {
5    List<String> headlineList=new ArrayList<>();
6    List<String> descriptionList=new ArrayList<>();
7
8    Context context;
9    int myPosition;
10    URL url;
11
12    public RecyclerAdapterClass(Context context, List<String> headlineList, List<String> descriptionList) {
13        this.context=context;
14        this.headlineList=headlineList;
15        this.descriptionList=descriptionList;
16   
17    }
18    @NonNull
19    @Override
20    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
21        LayoutInflater inflater=LayoutInflater.from(context);
22        View view=inflater.inflate(R.layout.single_item,parent,false);
23
24        return new MyViewHolder(view);
25    }
26    @Override
27    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
28
29   
30        holder.rowHeadline.setText(headlineList.get(position));
31        holder.rowDescription.setText(descriptionList.get(position))
32
33        holder.singleRowLayout.setOnClickListener(v -> { 		//Click event 
34
35            //Do what you want...
36        });
37    }
38    @Override
39    public int getItemCount() {
40        return headlineList.size();
41    }
42
43    public static class MyViewHolder extends RecyclerView.ViewHolder {
44        TextView rowHeadline,rowDescription;
45        Linearlayout singleRowLayout;
46
47        public MyViewHolder(@NonNull View itemView) {
48            super(itemView);
49          
50            rowHeadline=itemView.findViewById(R.id.rowHeadline);
51            rowDescription=itemView.findViewById(R.id.rowDescription);
52          
53            singleRowLayout=itemView.findViewById(R.id.singleItemLayout);
54
55        }
56    }
57        @SuppressLint("WrongThread")
58        @Override
59        protected void onPostExecute(Bitmap bitmap) {
60            super.onPostExecute(bitmap);
61
62        }
63        @Override
64        protected void onProgressUpdate(Void... values) {
65            super.onProgressUpdate(values);
66        }
67
68    }
69}