Recyclerview自定义点击事件(以及Fresco中SimpleDraweeView的使用)

依赖:

 

   compile 'com.android.support:recyclerview-v7:26.0.0-alpha1'
 
在Activity中设置Recyclerview的布局管理器:

    

     mRlv.setLayoutManager(new LinearLayoutManager(this));
        leftAdapter = new LeftAdapter(data, this);
        mRlv.setAdapter(leftAdapter);
        leftAdapter.setOnItemClickLisenter(new LeftAdapter.OnItemClickLisenter() {
            @Override
            public void onitemClick(int a) {
                 leftPersent.getRight("getProductCatagory",a);

Recyclerview的适配器

 

public class RightRLVAdapter extends RecyclerView.Adapter{
    private  List list;
    private Context context;
    private String s;


    public RightRLVAdapter( List list, Context context) {
        this.list = list;
        this.context = context;
    }

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

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        RightBean.DataBean.ListBean listBean = list.get(position);
        ViewHolder vh= (ViewHolder) holder;
        String icon = listBean.getIcon();
        Uri uri=Uri.parse(icon);

        vh.mTextView.setText(listBean.getName());
        vh.sdv.setImageURI(uri);
    }

    //获取数据的数量  
    @Override
    public int getItemCount() {
        return list.size();
    }
    //自定义的ViewHolder,持有每个Item的的所有界面元素  
    public static class ViewHolder extends RecyclerView.ViewHolder {
        public TextView mTextView;
       SimpleDraweeView sdv;
        public ViewHolder(View view){
            super(view);
            mTextView = (TextView) view.findViewById(R.id.tv2);
            sdv=view.findViewById(R.id.sdl);

        }
    }
    public interface OnItemClickLisenter{
        void onitemClick(int a);
    }
    private OnItemClickLisenter onItemClickLisenter;
    public void setOnItemClickLisenter(OnItemClickLisenter onItemClickLisenter){
        this.onItemClickLisenter=onItemClickLisenter;
    }
}

rightrvlitem的布局:



    




你可能感兴趣的:(安卓的控件使用)