多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# 基础使用 请看这篇文章 [基础使用教程](http://blog.csdn.net/yanbober/article/details/45307549) # 点餐APP中的用法: 第一步,初始化 ` final AsyncHttpClient client = new AsyncHttpClient();` 第二步发送get请求 ~~~ client.get(Constants.server_url + Constants.buyer_list_url, null, new AsyncHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) { AppLog.debug(new String(responseBody)); Gson gson = new Gson(); ProductVO productVO = gson.fromJson(new String(responseBody), ProductVO.class); AppLog.debug(productVO.getData().get(0).getFoods().get(0).getName()); //一个data就是一种商品类型 List<ProductVO.DataBean> dataBeanList = productVO.getData(); //组装商品类型 categorylist List<String> categoryName = new ArrayList<>(); //组装商品productlist final List<ProductItem> productItemList = new ArrayList<>(); final List<Integer> typesList = new ArrayList<>(); int flag = 0; for (ProductVO.DataBean dataBean : dataBeanList) { String categoryNameTMP = dataBean.getName(); AppLog.debug(categoryNameTMP); //组装类型名称 categoryName.add(categoryNameTMP); //获得商品列表 List<ProductVO.DataBean.FoodsBean> foods = dataBean.getFoods(); flag += foods.size(); typesList.add(flag);//每个商品类型有几个商品,第0个类型有 foods.zie个商品 for (ProductVO.DataBean.FoodsBean foodsBean : foods) { ProductItem productItem = new ProductItem(); productItem.setProductId(foodsBean.getId()); productItem.setImgUrl(foodsBean.getIcon()); productItem.setProductName(foodsBean.getName()); productItem.setProductDes(foodsBean.getDescription()); productItem.setProductPrice(foodsBean.getPrice()); //添加商品列表 productItemList.add(productItem); } } RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.VERTICAL, false); RecyclerView.LayoutManager layoutManager1 = new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.VERTICAL, false); rvProduct.setLayoutManager(layoutManager); ivProductCategory.setLayoutManager(layoutManager1); BaseQuickAdapter<String, BaseViewHolder> categoryAdapter = new HomeAdapterCategory(R.layout.product_category_item, categoryName); final BaseQuickAdapter<ProductItem, BaseViewHolder> infoProductAdapter = new HomeAdapter(R.layout.product_info_item, productItemList); //商品类型添加事件 categoryAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() { @Override public void onItemClick(BaseQuickAdapter adapter, View view, int position) { //position对应商品类型 int foodsposition = typesList.get(position); AppLog.debug(foodsposition); rvProduct.scrollToPosition(foodsposition); } }); infoProductAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() { @Override public void onItemChildClick(BaseQuickAdapter adapter, View view, final int position) { List<ProductItem> productItems = cartForm.getList(); if (view.getId() == R.id.btn_add_product_to_cart) { Integer amout = productItemList.get(position).getAmout(); productItemList.get(position).setAmout(amout + 1); AppLog.debug(amout + 1); ProductItem productItem = productItemList.get(position); productItems.add(productItem); } else if (view.getId() == R.id.btn_de_product_to_cart) { Integer amout = productItemList.get(position).getAmout(); if (amout > 0) { productItemList.get(position).setAmout(amout - 1); ProductItem productItem = productItemList.get(position); productItems.add(productItem); } AppLog.debug(amout - 1); } int sumCount = 0; int sumPrice = 0; for (ProductItem productItem : productItemList) { sumCount += productItem.getAmout(); if (productItem.getAmout() >= 1) { sumPrice += productItem .getProductPrice() * productItem.getAmout(); } } cartForm.setList(productItems); rvProduct.setAdapter(infoProductAdapter); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("总共").append(sumCount).append("件商品").append("共计").append(sumPrice).append("元"); tvShowCart.setText(stringBuilder); } }); rvProduct.setAdapter(infoProductAdapter); ivProductCategory.setAdapter(categoryAdapter); } @Override public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) { } }); ~~~