学习笔记 Tianmao 篇 recyclerView 辅助的RecycleAdapterImpl类(适配自定义care 一型 使用了frecso SimpleDraweeView)

本文介绍了一个基于RecyclerView.Adapter的封装实现案例,展示了如何通过自定义Adapter来管理列表项的展示和交互,包括Item布局定制、数据绑定及点击事件处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一 .这里是承接学习笔记 Tianmao 篇 RecyclerView.Adapter 的封装

二.这里只贴RecycleAdapterImpl类代码对应的javabean 和 布局 以及 相应的效果

三.规格为 效果图—Impl类 —javabean —布局—-style

1.效果图

这里写图片描述
这里写图片描述

2.Impl类

package pers.lijunxue.tianmao.adapter;

import android.content.Context;
import android.net.Uri;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;


import com.facebook.drawee.view.SimpleDraweeView;

import java.util.List;

import pers.lijunxue.tianmao.R;
import pers.lijunxue.tianmao.javabean.CareFirstViewBean;


/**
 * Created by rabook on 2016/10/27.
 */

public class CareFirstRecycleAdapterImpl extends BaseRecycleAdapter {

    public static final int VIEW_TYPE = 10;

    private LayoutInflater layoutInflater;

    public CareFirstRecycleAdapterImpl(List list, Context context) {
        super(list, context);
    }


    @Override
    RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        layoutInflater = LayoutInflater.from(parent.getContext());
        View view = layoutInflater.inflate(R.layout.care_item_card_view, parent, false);
        return new CareFirstRecycleAdapterImpl.CareFirstViewHolder(view);

    }

    @Override
    void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        CareFirstRecycleAdapterImpl.CareFirstViewHolder careFirstViewHolder = (CareFirstRecycleAdapterImpl.CareFirstViewHolder)holder;
        careFirstViewHolder.onBind(super.getList(),position,super.getContext());
    }


    // 绑定item布局文件中的子控件 监听动作
    class CareFirstViewHolder extends RecyclerView.ViewHolder {

        private CareFirstViewBean careFirstViewBean;
        private TextView title ;
        private TextView price ;
        private Button btn;
        private SimpleDraweeView drawee;



        public CareFirstViewHolder(View itemView) {

            super(itemView);

            drawee = (SimpleDraweeView) itemView.findViewById(R.id.drawee_view);
            title = (TextView) itemView.findViewById(R.id.text_title);
            price = (TextView) itemView.findViewById(R.id.text_price);
            btn = (Button) itemView.findViewById(R.id.btn_buy);



        }



        public void onBind(List list , int position, Context context){



            careFirstViewBean =  (CareFirstViewBean)list.get(position);
            Uri uri = Uri.parse(careFirstViewBean.getImgUrl());
            price.setText(""+careFirstViewBean.getPrice());
            drawee.setImageURI(uri);
            title.setText(careFirstViewBean.getName());
            btn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(getContext(),"你点击了"+careFirstViewBean.getName(), Toast.LENGTH_SHORT).show();
                }
            });

        }
    }
}

3.javabean

1.外层
package pers.lijunxue.tianmao.javabean;

import java.util.List;

/**
 * Created by rabook on 2016/10/27.
 */

public class CarePageBean<T>{


    private int currentPage ;
    private int pageSize ;
    private int totalPage ;
    private int totalCount;
    private List<T> list;





    public int getTotalCount() {
        return totalCount;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public List<T> getList() {
        return list;
    }


    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }
}
2.内层
package pers.lijunxue.tianmao.javabean;

import java.io.Serializable;

/**
 * Created by rabook on 2016/10/27.
 */

public class CareFirstViewBean extends ViewBean {

    public static final int TYPE = 11;

    private long id;
    private String name;
    private String imgUrl;
    private String description;
    private Float price;

    public CareFirstViewBean() {
        super(TYPE);
    }

    public long getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public String getImgUrl() {
        return imgUrl;
    }

    public String getDescription() {
        return description;
    }

    public Float getPrice() {
        return price;
    }

    public void setId(long id) {
        this.id = id;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setImgUrl(String imgUrl) {
        this.imgUrl = imgUrl;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public void setPrice(Float price) {
        this.price = price;
    }
}

4.布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <!--运用frecso动态地获取网络数据-->
    <com.facebook.drawee.view.SimpleDraweeView
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:background="@null"
        android:id="@+id/drawee_view"
        android:layout_alignParentLeft="true"
        app:viewAspectRatio="1"
        >

    </com.facebook.drawee.view.SimpleDraweeView>


    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_toRightOf="@+id/drawee_view">

        <TextView
            android:id="@+id/text_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/black"
            android:textSize="20sp"
            android:maxLines="3"
            android:text="题目"

            />

        <TextView
            android:id="@+id/text_price"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="30sp"
            android:textColor="@color/black"
            android:text="价格"
            />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:id="@+id/btn_buy"
            android:text="立即购买"
            android:layout_gravity="right|bottom"
            />


    </LinearLayout>
</RelativeLayout>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值