首页 > 代码库 > 测试标题

测试标题

package cn.andros230.glide;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

import java.util.List;

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
    private List<ImageBean.tngouBean> datas;
    private Context context;

    public MyAdapter(Context context, List<ImageBean.tngouBean> datas) {
        this.datas = datas;
        this.context = context;
    }

    //创建新View,被LayoutManager所调用
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item, viewGroup, false);
        ViewHolder vh = new ViewHolder(view);
        return vh;
    }

    //将数据与界面进行绑定的操作
    @Override
    public void onBindViewHolder(ViewHolder viewHolder, int position) {
        String url = datas.get(position).getImg();
        // System.out.println(url);
        if (url != null) {
            Glide.with(context)
                    .load("http://tnfs.tngou.net/image" + url)
                    .centerCrop()
                    .into(viewHolder.imageView);
        }


    }

    //获取数据的数量
    @Override
    public int getItemCount() {
        return datas.size() - 1;
    }

    //自定义的ViewHolder,持有每个Item的的所有界面元素
    public static class ViewHolder extends RecyclerView.ViewHolder {
        public ImageView imageView;

        public ViewHolder(View view) {
            super(view);
            imageView = (ImageView) view.findViewById(R.id.image);
        }
    }
}

 

测试标题