网友通过本文主要向大家介绍了硅谷商城,硅谷,硅谷亮城写字楼,济南硅谷培训学校,尚硅谷官网等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
硅谷商城4--显示购物车商品,硅谷商城4--购物车
1_购物车页面和标题栏的设置
govaffair_pager.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#802f4f4f"
android:gravity="center_vertical">
<CheckBox
android:id="@+id/checkbox_all"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:button="@drawable/selector_checkbox"
android:checked="true"
android:text="全选"
android:textColor="#88ffffff" />
<TextView
android:id="@+id/tv_total_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@id/checkbox_all"
android:text="合计 ¥40 "
android:textColor="#88ffffff"
android:textSize="28sp" />
<Button
android:id="@+id/btn_order"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginBottom="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:background="@drawable/btn_bg_selector"
android:padding="8dp"
android:text="去结算"
android:textColor="@android:color/white" />
<Button
android:id="@+id/btn_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginBottom="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:background="@drawable/btn_bg_selector"
android:padding="10dp"
android:text="删除"
android:textColor="@android:color/white"
android:visibility="gone" />
</RelativeLayout>
</LinearLayout>
2_设置适配器
public class GovaffairPagerAdapter extends RecyclerView.Adapter<GovaffairPagerAdapter.ViewHolder> {
private final Context context;
private final List<ShopingCart> datas;
public GovaffairPagerAdapter(Context context, List<ShopingCart> datas) {
this.context = context;
this.datas = datas;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = View.inflate(context, R.layout.item_govaffairpager, null);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
ShoppingCart wares = datas.get(position);
//加载图片
Glide.with(context).load(wares.getImgUrl()).
placeholder(R.drawable.news_pic_default).
error(R.drawable.news_pic_default)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(holder.iv_icon);
holder.checkbox.setChecked(cart.isChecked());
holder.tv_name.setText(wares.getName());
holder.tv_price.setText("¥ "+wares.getPrice());
holder.numberAddSubView.setValue(wares.getCount());
}
@Override
public int getItemCount() {
return datas.size();
}
class ViewHolder extends RecyclerView.ViewHolder {
private CheckBox checkbox;
private ImageView iv_icon;
private TextView tv_name;
private TextView tv_price;
private NumberAddSubView numberAddSubView;
public ViewHolder(View itemView) {
super(itemView);
checkbox = (CheckBox) itemView.findViewById(R.id.checkbox);
iv_icon = (ImageView) itemView.findViewById(R.id.iv_icon);
tv_name = (TextView) itemView.findViewById(R.id.tv_name);
tv_price = (TextView) itemView.findViewById(R.id.tv_price);
numberAddSubView = (NumberAddSubView) itemView.findViewById(R.id.numberAddSubView);
}
}
}


