一 .这里是承接学习笔记 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>