1_購物車頁面和標題欄的設置 govaffair_pager.xml 2_設置適配器 ...
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); } } }