Silicon Valley Mall 4-display shopping cart items, Silicon Valley Mall 4-shopping cart
1 _ settings of the shopping cart page and title bar
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 = "select all" android: textColor = "#88 ffffff"/> <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 40" android: textColor = "#88 ffffff" 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 = "Settlement" 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 = "delete" android: textColor = "@ android: color/white" android: visibility = "gone"/> </RelativeLayout> </LinearLayout>
2 _ set the adapter
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); // load the image 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 );}}}