import android.media.Image;
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;
import java.util.List;
public class RecyclerViewAdapter extends RecyclerView.Adapter {
public List mlist;
static class ViewHolder extends RecyclerView.ViewHolder{
ImageView imageView;
TextView textView;
public ViewHolder(@NonNull View itemView) {
super(itemView);
imageView=(ImageView)itemView.findViewById(R.id.image);
textView=(TextView)itemView.findViewById(R.id.title);
}
}
public RecyclerViewAdapter(List list) {
this.mlist =list;
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.main_item,parent,false);
ViewHolder holder=new ViewHolder(view);
return holder;
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
ItemBean itemBean = mlist.get(position);
holder.imageview.setImageResource(itemBean.getImage());
holder.textView.setText(itemBean.getText());
}
@Override
public int getItemCount() {
return mlist.size();
}
}