Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.recyclerview;
- import android.content.Context;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.ImageView;
- import android.widget.TextView;
- import androidx.annotation.NonNull;
- import androidx.recyclerview.widget.RecyclerView;
- public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyHolder> {
- String data1[],data2[];
- int img[];
- Context ctx;
- public MyAdapter(Context ct,String s1[],String s2[],int arr[])
- {
- data1=s1;
- data2=s2;
- ctx=ct;
- img=arr;
- }
- @NonNull
- @Override
- public MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
- LayoutInflater myinflator=LayoutInflater.from(ctx);
- View MyView=myinflator.inflate(R.layout.my_row,parent,false);
- return new MyHolder(MyView);
- }
- @Override
- public void onBindViewHolder(@NonNull MyHolder holder, int position) {
- holder.t1.setText(data1[position]);
- holder.t2.setText(data2[position]);
- holder.myimage.setImageResource(img[position]);
- }
- @Override
- public int getItemCount() {
- return data1.length;
- }
- public class MyHolder extends RecyclerView.ViewHolder {
- TextView t1,t2;
- ImageView myimage;
- public MyHolder(@NonNull View itemView) {
- super(itemView);
- t1=(TextView)itemView.findViewById(R.id.textView);
- t2=(TextView)itemView.findViewById(R.id.textView2);
- myimage=(ImageView)itemView.findViewById(R.id.imageView);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment