ListView适配器

package com.qy.glide.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.qy.glide.R;
import com.qy.glide.bean.JsonBean;

import java.util.ArrayList;
import java.util.List;

public class MyAdapter extends BaseAdapter {
private ArrayList list;
private Context context;

public MyAdapter(ArrayList list, Context context) {
    this.list = list;
    this.context = context;
}

@Override
public int getCount() {
    return list.size();
}

@Override
public Object getItem(int position) {
    return null;
}

@Override
public long getItemId(int position) {
    return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    convertView = View.inflate(context, R.layout.item, null);
    ImageView imageView = convertView.findViewById(R.id.imageView);
    TextView textView = convertView.findViewById(R.id.textView);

    JsonBean.DataBean dataBean = list.get(position);
    textView.setText(dataBean.getBookname());
    //设置图片
    Glide.with(context).load(dataBean.getBook_cover()).into(imageView);
    return convertView;
}

}

你可能感兴趣的:(ListView适配器)