购物车(ShoppingCar)
来源:互联网 发布:ajax json java前端 编辑:程序博客网 时间:2024/05/22 08:12
================main_activity===============================
package com.example.lenovo.shoppingcar.view;import android.os.Bundle;import android.os.Handler;import android.os.Message;import android.support.v7.app.AppCompatActivity;import android.view.View;import android.widget.CheckBox;import android.widget.LinearLayout;import android.widget.RelativeLayout;import android.widget.TextView;import android.widget.Toast;import wangaimin.bwie.com.example.lenovo.shoppingcar.R;import wangaimin.bwie.com.example.lenovo.shoppingcar.model.bean.CartBean;import wangaimin.bwie.com.example.lenovo.shoppingcar.model.bean.CountPriceBean;import wangaimin.bwie.com.example.lenovo.shoppingcar.presenter.CartPresenter;import wangaimin.bwie.com.example.lenovo.shoppingcar.util.ApiUtil;import wangaimin.bwie.com.example.lenovo.shoppingcar.view.IView.IMainActivity;import wangaimin.bwie.com.example.lenovo.shoppingcar.view.adapter.MyAdapter;import wangaimin.bwie.com.example.lenovo.shoppingcar.view.custom.CartExpanableListview;public class CartActivity extends AppCompatActivity implements IMainActivity, View.OnClickListener{ private CartExpanableListview expanableListview; private CartPresenter cartPresenter; private CheckBox check_all; private TextView text_total; private TextView text_buy; private CartBean cartBean; private RelativeLayout relative_progress; private MyAdapter myAdapter; private LinearLayout linear_bottom; private Handler handler = new Handler(){ @Override public void handleMessage(Message msg) { if (msg.what == 0){ CountPriceBean countPriceBean = (CountPriceBean) msg.obj; text_total.setText("合计:¥"+countPriceBean.getPriceString()); text_buy.setText("去结算("+countPriceBean.getCount()+")"); } } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.cart_activity_layout); check_all = (CheckBox) findViewById(R.id.check_all); text_total = (TextView) findViewById(R.id.text_total); text_buy = (TextView) findViewById(R.id.text_buy); expanableListview = (CartExpanableListview) findViewById(R.id.expanable_listview); relative_progress = (RelativeLayout) findViewById(R.id.relative_progress); linear_bottom = (LinearLayout) findViewById(R.id.linear_layout); //去掉默认的指示器 expanableListview.setGroupIndicator(null); cartPresenter = new CartPresenter(this); //1.点击全选:选中/未选中...调用适配器中的方法...myAdapter.setIsCheckAll(true);来设置所有的一级和二级是否选中,计算 check_all.setOnClickListener(this); text_buy.setOnClickListener(this); } @Override protected void onResume() { super.onResume(); relative_progress.setVisibility(View.VISIBLE); //请求数据 cartPresenter.getCartData(ApiUtil.cartUrl); } @Override public void getSuccessCartData(CartBean cartBean) { relative_progress.setVisibility(View.GONE); this.cartBean = cartBean; if (cartBean != null){ //显示下面的 linear_bottom.setVisibility(View.VISIBLE); //1.根据组中子条目是否选中,,,决定该组是否选中...初始化一下每一组中isGroupCheck这个数据 for (int i = 0;i<cartBean.getData().size();i++){ if (isAllChildInGroupSelected(i)){ //更改i位置 组的选中状态 cartBean.getData().get(i).setGroupChecked(true); } } //2.根据每一个组是否选中的状态,,,初始化全选是否选中 check_all.setChecked(isAllGroupChecked()); //设置适配器 myAdapter = new MyAdapter(CartActivity.this, cartBean,handler,cartPresenter,relative_progress); expanableListview.setAdapter(myAdapter); //展开 for (int i= 0;i<cartBean.getData().size();i++){ expanableListview.expandGroup(i); } //3.根据子条目是否选中 初始化价格和数量 myAdapter.sendPriceAndCount(); }else { //隐藏下面的全选.... 等 linear_bottom.setVisibility(View.GONE); //显示去逛逛,,,添加购物车 Toast.makeText(CartActivity.this,"购物车为空,去逛逛",Toast.LENGTH_SHORT).show(); } } /** * 所有的一级列表是否选中 */ private boolean isAllGroupChecked() { for (int i =0;i<cartBean.getData().size();i++){ if (! cartBean.getData().get(i).isGroupChecked()){//代表一级列表有没选中的 return false; } } return true; } /** * 判断当前组里面所有的子条目是否选中 * @param groupPosition * @return */ private boolean isAllChildInGroupSelected(int groupPosition) { for (int i= 0;i<cartBean.getData().get(groupPosition).getList().size();i++){ //只要有一个没选中就返回false if (cartBean.getData().get(groupPosition).getList().get(i).getSelected() ==0){ return false; } } return true; } @Override public void onClick(View view) { switch (view.getId()){ case R.id.check_all: myAdapter.setAllChildState(check_all.isChecked()); break; case R.id.text_buy://去结算...试一下创建订单 break; } }}==================activity_main==================================
<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="wangaimin.bwie.com.example.lenovo.shoppingcar.view.CartActivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /></android.support.constraint.ConstraintLayout>
阅读全文
0 0
- 购物车(ShoppingCar)
- angularJs shoppingCar
- 购物车
- 购物车
- 购物车
- 购物车
- 购物车
- 购物车
- 购物车
- 购物车
- 购物车
- 购物车
- 购物车
- 购物车
- 购物车
- 购物车
- 购物车
- 购物车
- ScrollView滑动监听显示标题栏
- El表达式中的常用符号含义
- CentOS 6.5自动获取IP地址
- 安卓获得屏幕高度和宽度的几种方法
- 静态方法被重写???
- 购物车(ShoppingCar)
- [unfinished]论文阅读《CondenseNet: An Efficient DenseNet using Learned Group Convolutions 》
- 程序设计——校园导游系统
- 10037---MySQL修改root密码的各种方法整理
- jquery表单选择器
- 个人中心主页
- 本地图片预览+blob使用
- RxJava简单使用
- Qt实现Socket断线重连机制