Example #1
0
 private void flushCartInfo() {
   settleNum = 0;
   bottom_container.setVisibility(View.GONE);
   Utils.asyncHttpRequestGet(
       Constants.URL_CARTINFO,
       null,
       new JsonHttpResponseHandler() {
         @Override
         public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
           if (statusCode != 200) {
             Toast.makeText(CartActivtiy.this, statusCode, Toast.LENGTH_SHORT).show();
             return;
           }
           com.app.commons.JSONObject jo = new com.app.commons.JSONObject(response);
           if (jo.getBoolean("success")) {
             container.removeAllViews();
             jo = jo.getJSONObject("result");
             if (jo != null) jo = jo.getJSONObject("shopCart");
             if (jo != null) {
               flag = jo.getBoolean("flag");
               JSONArray ja = jo.getJSONArray("productList");
               if (ja != null && ja.length() > 0) {
                 bottom_container.setVisibility(View.VISIBLE);
               }
               total.setText(jo.getString("amount"));
               discountPrice.setText(jo.getString("discountPrice"));
               LinearLayout cart;
               for (int i = 0, j = ja.length(); i < j; i++) {
                 cart = createProductInfo(ja.getJSONObject(i));
                 if (cart != null) {
                   container.addView(cart);
                 }
               }
             } else {
               Button btn = new Button(CartActivtiy.this);
               LinearLayout.LayoutParams llp =
                   new LinearLayout.LayoutParams(
                       ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
               llp.gravity = Gravity.CENTER;
               llp.setMargins(0, 100, 0, 0);
               btn.setLayoutParams(llp);
               btn.setText(getResources().getString(R.string.no_cart_info));
               btn.setTextColor(getResources().getColor(R.color.white));
               btn.setBackgroundResource(R.drawable.btn_primary);
               btn.setOnClickListener(
                   new View.OnClickListener() {
                     @Override
                     public void onClick(View view) {
                       Intent intent = new Intent();
                       intent.setClass(CartActivtiy.this, MainActivity.class);
                       startActivity(intent);
                     }
                   });
               container.addView(btn);
             }
           } else {
             Toast.makeText(CartActivtiy.this, jo.getString("errMsg"), Toast.LENGTH_SHORT).show();
           }
         }
       });
 }