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();
}

  • vicky    2020-02-14 11:48:10
  • 阅读 741    收藏 0    回答 1
  • 邀请
  • 收藏
  • 分享
发送
登录 后发表评论
  • 51testing软件测试圈微信