二级列表购物车

一导依赖mycartutils(购物车)   okhttputils(网络请求)

二将mycartutils下的版本改为minSdkVersion 15

主布局

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" tools:context="com.bwei.shoppingdemozong.MainActivity">

    <ExpandableListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/ex"
        android:layout_weight="1"
        ></ExpandableListView>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal">

        <CheckBox
            android:id="@+id/all"
            android:layout_width="50dp"
            android:layout_height="50dp" />

        <TextView
            android:id="@+id/count"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="数量" />

        <TextView
            android:id="@+id/name"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="价钱" />
    </LinearLayout>
</LinearLayout>
 
 
主类
public class MainActivity extends AppCompatActivity {
    private ExpandableListView ex;
    private TextView price;
    private TextView count;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ex = (ExpandableListView) findViewById(R.id.ex);
        final CheckBox all = (CheckBox) findViewById(R.id.all);
        count = (TextView) findViewById(R.id.count);
        price = (TextView) findViewById(R.id.name);

        HttpUtils.doGet("http://www.yulin520.com/a2a/impressApi/news/mergeList?sign=C7548DE604BCB8A17592EFB9006F9265&pageSize=20&gender=2&ts=1871746850&page=1 ", new HttpUtils.GsonObjectCallback<JavaBean>() {
            @Override
            public void onUi(JavaBean javaBean) {
                List<JavaBean.DataBean> data = javaBean.getData();

                List<GroupBean> groupBeen = new ArrayList<GroupBean>();
                List<List<ChildBean>> child = new ArrayList<List<ChildBean>>();

                for (int i = 0; i < data.size(); i++) {
                    groupBeen.add(new GroupBean(data.get(i).getTitle(), false));
                }
                for (int i = 0; i < data.size(); i++) {
                    List<ChildBean> ch = new ArrayList<ChildBean>();
                    for (int j = 0; j < data.size(); j++) {
                        ch.add(new ChildBean(data.get(j).getTitle(), "100", data.get(j).getImg(), false, 1));
                    }

                    child.add(ch);
                }
                //依赖中的方法
                CartUtils.setCartData(MainActivity.this, groupBeen, child, ex, all, price, count);
            }

            @Override
            public void onFailed(Call call, IOException e) {

            }
        });

    }
}

四将okhttputils下的三个类复制到工程里
调方法
 


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值