ProgressDialog在android活动中保持打开状态

时间:2014-04-29 06:08:58

标签: android android-asynctask progressdialog

我做了一个活动,因为我正在使用AsyncTak进行api调用,我在DoBackground方法中显示了progressDialog,并希望在postExecute中忽略progressDialog我已经这样做但是它不起作用,我的progressDialog仍然存在,操作后打开..我的代码如下,anybuddy可以帮我解散。

main.java

   package com.epe.yehki.ui;

import java.util.ArrayList;
import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Paint.Join;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewDebug.FlagToString;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.epe.yehki.backend.BackendAPIService;
import com.epe.yehki.backend.FavoriteAPI;
import com.epe.yehki.backend.ResponseListener;
import com.epe.yehki.uc.Menu;
import com.epe.yehki.util.Const;
import com.epe.yehki.util.Const.API_RESULT;
import com.epe.yehki.util.Pref;
import com.epe.yehki.util.Utils;
import com.example.yehki.R;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

public class WholesaleProductDetailActivity extends Activity {
    public ImageView productImage;
    private ImageLoader imageLoader;
    private DisplayImageOptions options;
    private ProgressDialog pDialog;
    JSONArray proDetails = null;
    private Menu menu;
    Intent i1;
    private FavoriteAPI favApi;
    private int isFavourite;
    private ProgressDialog progressDialog;

    // CONTROLLS FOR WHOLESALE RETAILS.........!!!

    TextView retailPrice;
    TextView tv_moqW;
    TextView tv_moqR;
    TextView tv_shipping_cost;
    TextView EscrowPayment;
    TextView ProcessigPeriod;
    LinearLayout llQuantity;
    EditText quantity;
    LinearLayout llbotm;
    TextView tv_escrow_payment;
    TextView tv_procesiing_period;
    Button contactSuplier, addToCart, buyNOw;
    LinearLayout ll_botom1;

    // ************************

    // strings.......!!!
    String pro_id;
    String name;
    String retail_price;
    String price_wholesale;
    String keywords;
    String supplier_id;
    String supplier_name;
    String listing_description;
    String image;
    String Specifications;
    String date_added;
    String status;
    int flag = 0;
    String port;
    String customer_name;
    String customer_id;
    String cId;
    String min_order_qty_retail;
    String min_order_qty_wholesale;
    String countyId;
    String supply_amount;
    String msg;
    String supply_unit_id;
    String supply_unit_name;
    String supply_time;
    String payment_terms;
    String min_order_qty;
    String min_order_qty_unit;
    String min_order_qty_unit_name;
    String delivery_time;
    String company_name;
    String country_id;
    String state_id;
    String procesPeriod;

    // COMPANY DETAILS....
    String companyDetail;
    String companyDetailName;
    String companyDetailAddress;
    String companyDetailPhoto;
    String companyDetailMainProduct;
    String companyDetailotherProduct;
    String cartNo;

    // PRODUCT QUICK DETAILS...

    // TextViews.............!!!
    public TextView productName;
    public TextView wholeSalePrice;
    public TextView minOrder;
    public TextView shippingCost;
    public TextView escrowPayment;
    public TextView processingPeriod;
    public TextView compnyName;
    public TextView countryName;
    public TextView bussinessType;
    public TextView mainProduct;
    public TextView productDetails;
    public String pid;

    // Buttons of placeOrder and contact supplier..

    private Button contactSupplier;

    private ImageView iv_back;
    private TextView cart;
    private ImageView iv_fav;
    public Intent i;

    //

    // Hashmap for ListView
    ArrayList<HashMap<String, String>> ProductDetailList;

    // URL to get contacts JSON
    // API_PRODUCT?product_id=29
    private static String productUrl;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_product_detail);
        initializeViews();
        cId = Pref.getValue(WholesaleProductDetailActivity.this, Const.PREF_CUSTOMER_ID, "");
        ll_botom1 = (LinearLayout) findViewById(R.id.ll_botom1);
        ll_botom1.setVisibility(View.VISIBLE);
        imageLoader = ImageLoader.getInstance();
        imageLoader.init(ImageLoaderConfiguration.createDefault(WholesaleProductDetailActivity.this));

        options = new DisplayImageOptions.Builder().cacheOnDisc(true).showImageOnFail(R.drawable.logo).build();
        new AddToCart().execute();

        // get extras..............!!!!
        i = getIntent();

        i.getStringExtra(Const.TAG_PRODUCT_NAME);
        i.getStringExtra(Const.TAG_PRODUCT_IMG);
        pid = i.getStringExtra(Const.TAG_PRODUCT_ID);

        favApi = new FavoriteAPI(WholesaleProductDetailActivity.this, responseListener, pid, Pref.getValue(WholesaleProductDetailActivity.this, Const.PREF_CUSTOMER_ID, ""));
        favApi.callApi();

        // bACK BUTTON.......!
        iv_back.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                finish();
            }
        });

        // DO FAVOURITE YOUR PRODUCT..........!!!
        iv_fav.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {

                // CHECKING IS USER lOGIN...!
                if (Pref.getValue(WholesaleProductDetailActivity.this, Const.PREF_CUSTOMER_ID, "") != null
                        && !Pref.getValue(WholesaleProductDetailActivity.this, Const.PREF_CUSTOMER_ID, "").equals("")) {
                    // FAVOURITE API CALL..........!!!

                    if (iv_fav.isSelected()) {
                        isFavourite = 0;
                        iv_fav.setImageResource(R.drawable.star);
                        iv_fav.setSelected(false);

                    } else {
                        isFavourite = 1;
                        iv_fav.setImageResource(R.drawable.star_filled);
                        iv_fav.setSelected(true);
                    }
                    if (Utils.isOnline(WholesaleProductDetailActivity.this)) {

                        progressDialog = new ProgressDialog(WholesaleProductDetailActivity.this);
                        progressDialog.setMessage(getString(R.string.process_progress_msg));
                        progressDialog.setIndeterminate(true);
                        progressDialog.setCancelable(false);
                        progressDialog.show();

                        favApi = new FavoriteAPI(WholesaleProductDetailActivity.this, responseListener, pid, Pref.getValue(WholesaleProductDetailActivity.this, Const.PREF_CUSTOMER_ID, ""));
                        favApi.callApi();

                    } else {
                        Toast.makeText(WholesaleProductDetailActivity.this, "Please check your interenet connection", Toast.LENGTH_SHORT).show();
                    }

                } else {
                    i = new Intent(WholesaleProductDetailActivity.this, LoginActivity.class);
                    startActivity(i);
                }

            }
        });

        productUrl = Const.API_WHOLESALE_PRODUCT_DETAIL + "?" + Const.TAG_PRODUCT_ID + "=" + pid;
        System.out.println(":::::::::::PRODUCT URL:::::::::::::::" + productUrl);
        productName.setText(i.getStringExtra(Const.TAG_PRODUCT_NAME));
        try {
            imageLoader.displayImage(i.getStringExtra(Const.TAG_PRODUCT_IMG), productImage, options);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            productImage.setBackgroundResource(R.drawable.logo);
        }
        new GetProductDetails().execute();
        buyNOw.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                if (quantity.getText().toString() != null && !quantity.getText().toString().equals("")) {

                    if (Double.parseDouble(quantity.getText().toString()) < (Double.parseDouble(min_order_qty_retail))) {
                        Utils.showCustomeAlertValidation(WholesaleProductDetailActivity.this, "Please Enter Quantity greater than min. retail quamtity", "Yehki", "Ok");
                    } else {

                        i1 = new Intent(WholesaleProductDetailActivity.this, WholesalePlaceOrderActivity.class);

                        i1.putExtra(Const.TAG_PRODUCT_NAME, name);
                        i1.putExtra(Const.TAG_PRODUCT_ID, pid);
                        i1.putExtra("QTY_RETAIL", min_order_qty_retail);
                        i1.putExtra("QTY_WHOLESALE", min_order_qty_wholesale);
                        i1.putExtra(Const.TAG_PRODUCT_SUPPLEY_UNIT_ID, supply_unit_id);
                        i1.putExtra(Const.TAG_PRODUCT_SUPPLY_UNIT_NAME, supply_unit_name);
                        i1.putExtra(Const.TAG_PRODUCT_MAX_PRICE, price_wholesale);
                        i1.putExtra(Const.TAG_PRODUCT_MIN_PRICE, retail_price);
                        i1.putExtra("takenQTY", quantity.getText().toString());

                        if (Double.parseDouble(quantity.getText().toString()) > (Double.parseDouble(min_order_qty_retail))
                                && Double.parseDouble(quantity.getText().toString()) < (Double.parseDouble(min_order_qty_wholesale))) {
                            i1.putExtra("price", retail_price);
                            startActivity(i1);
                        } else if (Double.parseDouble(quantity.getText().toString()) > (Double.parseDouble(min_order_qty_wholesale))) {
                            i1.putExtra("price", price_wholesale);
                            startActivity(i1);
                        }

                    }

                } else {
                    Utils.showCustomeAlertValidation(WholesaleProductDetailActivity.this, "Please Enter Quantity", "Yehki", "Ok");
                }

            }
        });
        contactSuplier.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                i = new Intent(WholesaleProductDetailActivity.this, ContactSupplierActivity.class);
                i.putExtra(Const.TAG_SUPPLIER_ID, supplier_id);
                System.out.println("::::::::::::::::;my supplier id>>>>>>>>>>>>>>+++++++++++++++++" + supplier_id);
                i.putExtra(Const.TAG_PRODUCT_ID, pid);
                startActivity(i);

            }
        });
        addToCart.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (!quantity.getText().toString().equals("") && quantity.getText().toString() != null) {
                    new AddToCart().execute();
                } else {
                    Utils.showCustomeAlertValidation(WholesaleProductDetailActivity.this, "Please enter quanitity", "Yehki", "Ok");
                }
            }
        });

    }

    // ****INITIALIZING THE VIEWS.....!!!!!!!!!!!!!!!
    private void initializeViews() {
        productImage = (ImageView) findViewById(R.id.iv_product);
        productName = (TextView) findViewById(R.id.tv_product_name);
        buyNOw = (Button) findViewById(R.id.tv_place_order);
        contactSupplier = (Button) findViewById(R.id.tv_contact_suplier);
        wholeSalePrice = (TextView) findViewById(R.id.tv_price_range);
        minOrder = (TextView) findViewById(R.id.tv_min_order);
        shippingCost = (TextView) findViewById(R.id.tv_sply);
        escrowPayment = (TextView) findViewById(R.id.tv_payment_terms);
        processingPeriod = (TextView) findViewById(R.id.tv_port);
        compnyName = (TextView) findViewById(R.id.tv_company_name);
        countryName = (TextView) findViewById(R.id.tv_contry);
        bussinessType = (TextView) findViewById(R.id.tv_bussiness_type);
        mainProduct = (TextView) findViewById(R.id.tv_main_products);
        productDetails = (TextView) findViewById(R.id.tv_pro_detail);
        menu = (Menu) findViewById(R.id.menuProduct);
        iv_back = (ImageView) findViewById(R.id.iv_back);
        iv_fav = (ImageView) findViewById(R.id.iv_fvrt);
        cart = (TextView) findViewById(R.id.tv_cart);
        retailPrice = (TextView) findViewById(R.id.tv_retail_price);
        tv_moqW = (TextView) findViewById(R.id.tv_moqw);
        tv_moqR = (TextView) findViewById(R.id.tv_min_order);
        tv_shipping_cost = (TextView) findViewById(R.id.tv_shipping_cost);
        tv_escrow_payment = (TextView) findViewById(R.id.tv_escrow_payment);
        tv_procesiing_period = (TextView) findViewById(R.id.tv_procesiing_period);
        quantity = (EditText) findViewById(R.id.et_qty);
        llQuantity = (LinearLayout) findViewById(R.id.ll_btm);
        llQuantity.setVisibility(View.VISIBLE);
        llbotm = (LinearLayout) findViewById(R.id.ll_botom1);
        llbotm.setVisibility(View.VISIBLE);
        tv_shipping_cost.setText("Shipping Cost:");
        tv_escrow_payment.setText("Escrow Payment:");
        tv_procesiing_period.setText("Processing Period:");
        contactSuplier = (Button) findViewById(R.id.tv_contc_sup);
        addToCart = (Button) findViewById(R.id.btn_add_cart);
        buyNOw = (Button) findViewById(R.id.btn_buy);
        retailPrice.setVisibility(View.VISIBLE);
        menu.setSelectedTab(1);
    }

    private class GetProductDetails extends AsyncTask<Void, Void, Void> {

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            // Showing progress dialog
            pDialog = new ProgressDialog(WholesaleProductDetailActivity.this);
            pDialog.setMessage("Please wait...");
            pDialog.setCancelable(false);
            pDialog.show();
            System.out.println("==========inside preexecute===================");

        }

        @Override
        protected Void doInBackground(Void... arg0) {
            // Creating service handler class instance
            BackendAPIService sh = new BackendAPIService();

            // Making a request to url and getting response
            String jsonStr = sh.makeServiceCall(productUrl, BackendAPIService.GET);

            Log.d("Response: ", "> " + jsonStr);
            System.out.println("=============MY RESPONSE==========" + jsonStr);

            if (jsonStr != null) {
                try {
                    JSONObject jsonObj = new JSONObject(jsonStr);

                    // Getting JSON Array node
                    if (jsonObj.has(Const.TAG_PRODUCT_DETAIL)) {
                        // yes
                        proDetails = jsonObj.getJSONArray(Const.TAG_PRODUCT_DETAIL);

                        System.out.println("==========inside doIn background===================");
                        // looping through All Contacts
                        for (int i = 0; i < proDetails.length(); i++) {
                            JSONObject c = proDetails.getJSONObject(i);

                            name = c.getString(Const.TAG_PRODUCT_NAME);
                            keywords = c.getString(Const.TAG_PRODUCT_KEYWORDS);
                            supplier_id = c.getString(Const.TAG_PRODUCT_SUPPLIER_ID);
                            supplier_name = c.getString(Const.TAG_PRODUCT_SUPPLIER_NAME);
                            listing_description = c.getString(Const.TAG_PRODUCT_LISTING_DESCRIPTION);
                            image = c.getString(Const.TAG_PRODUCT_IMG);
                            Specifications = c.getString(Const.TAG_PRODUCT_SPECIFICATION);
                            date_added = c.getString(Const.TAG_PRODUCT_DATE_ADDED);

                            customer_name = c.getString(Const.TAG_PRODUCT_CUSTMER_NAME);
                            customer_id = c.getString(Const.TAG_PRODUCT_CUSTOMER_ID);

                            retail_price = c.getString(Const.TAG_PRICE_RETAIL);
                            price_wholesale = c.getString(Const.TAG_PRICE_WHOLESALE);
                            System.out.println(":::::::::::::My wholesale price:::::::::>>>>>>>" + price_wholesale);
                            min_order_qty_retail = c.getString(Const.TAG_MIN_ORDER_QTY_RETAIL);
                            System.out.println(":::::::::::::My wholesale price:::::::::>>>>>>>" + min_order_qty_retail);
                            min_order_qty_wholesale = c.getString(Const.TAG_MIN_ORDER_QTY_WHOLESALE);
                            System.out.println(":::::::::::::My wholesale price:::::::::>>>>>>>" + min_order_qty_wholesale);
                            countyId = c.getString(Const.TAG_COUNTRY_ID);
                            state_id = c.getString(Const.TAG_STATE_WHOLESALE_ID);

                            supply_unit_id = c.getString(Const.TAG_PRODUCT_SUPPLEY_UNIT_ID);
                            supply_unit_name = c.getString(Const.TAG_PRODUCT_SUPPLY_UNIT_NAME);
                            System.out.println("::::::::::::::::mY supply unit name::::::::::::::");
                            supply_time = c.getString(Const.TAG_PRODUCT_SUPPLY_TIME);
                            delivery_time = c.getString(Const.TAG_DELIVERY_TIME_WHOLESALE);

                            System.out.println(":::::::::::::::supply unit name:::::::::::::::::::" + delivery_time);

                            company_name = c.getString(Const.TAG_PRODUCT_COMPANY_NAME);
                            System.out.println(":::::::::::::::supply unit name:::::::::::::::::::" + company_name);

                            // GETTING COMPANY DETAILS..........!!!
                            JSONObject companyDetails = c.getJSONObject(Const.TAG_PRODUCT_COMPANY_DETAILS);
                            companyDetailName = companyDetails.getString(Const.TAG_PRODUCTDETAIL_COMPANY_NAME);
                            companyDetailAddress = companyDetails.getString(Const.TAG_PRODUCTDETAIL_COMPANY_ADDRESS);
                            companyDetailMainProduct = companyDetails.getString(Const.TAG_PRODUCTDETAIL_COMPANY_MAIN_PRODUCT);
                            companyDetailotherProduct = companyDetails.getString(Const.TAG_PRODUCTDETAIL_COMPANY_OTHER_PRODUCT);
                            companyDetailPhoto = companyDetails.getString(Const.TAG_PRODUCTDETAIL_PHOTO);
                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            } else {
                Log.e("ServiceHandler", "Couldn't get any data from the url");
            }

            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);
            // Dismiss the progress dialog
            if (pDialog != null) {
                pDialog.dismiss();
            }
            productName.setText(name);
            wholeSalePrice.setText("WholeSale Price:" + " " + price_wholesale);
            retailPrice.setText("Retail Price:" + " " + retail_price);
            tv_moqW.setText("MoqW:" + min_order_qty_wholesale);
            minOrder.setText("MoqR:" + min_order_qty_retail);
            shippingCost.setText("");
            escrowPayment.setText(payment_terms);
            compnyName.setText(company_name);
            countryName.setText(country_id);
            mainProduct.setText(companyDetailMainProduct);
            processingPeriod.setText(delivery_time);
        }
    }

    // RESPONSE lISTENER FOR THE FAVOURITE......!!
    ResponseListener responseListener = new ResponseListener() {

        @Override
        public void onResponce(String api, API_RESULT result, Object obj) {

            if (progressDialog != null) {
                progressDialog.dismiss();
            }
            if (api.equals(Const.API_DO_FAVOURITE)) {
                if (result == Const.API_RESULT.SUCCESS) {
                    System.out.println("::::::::::::::::;INSIDE SUCCESS ACTIVITY OF FAVORITE:::::::::;");
                }
            }

        }
    };

    // *********************ADD TO CART CALL...

    // *******************

    private class AddToCart extends AsyncTask<Void, Void, Void> {

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            // Showing progress dialog
            pDialog = new ProgressDialog(WholesaleProductDetailActivity.this);
            pDialog.setMessage("Please wait...");
            pDialog.setCancelable(false);
            pDialog.show();
            System.out.println("==========inside preexecute===================");

        }

        @Override
        protected Void doInBackground(Void... arg0) {
            String addToCArt = Const.API_ADD_TO_CART + "?customer_id=" + cId + "&product_id=" + pid + "&quantity=" + quantity.getText().toString() + "&unit_id=" + supply_unit_id; // Creating
                                                                                                                                                                                    // service
            // handler
            // class
            // instance
            BackendAPIService sh = new BackendAPIService();
            System.out.println(":::::::::::::MY add to cart url:::::::::::;" + addToCArt);
            // Making a request to url and getting response
            String jsonStr = sh.makeServiceCall(addToCArt, BackendAPIService.GET);

            Log.d("Response: ", "> " + jsonStr);
            System.out.println("=============MY RESPONSE==========" + jsonStr);

            if (jsonStr != null) {
                try {
                    JSONObject jsonObj = new JSONObject(jsonStr);

                    if (jsonObj.has(Const.TAG_STATUS)) {
                        status = jsonObj.getString(Const.TAG_STATUS);

                        if (status.equalsIgnoreCase("success")) {
                            flag = 1;
                            msg = jsonObj.getString(Const.TAG_MESSAGE);
                            cartNo = jsonObj.getString(Const.TAG_TOTAL_CART_PRODUCTS);
                        } else {
                            flag = 2;
                            msg = jsonObj.getString(Const.TAG_MESSAGE);
                        }

                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            } else {
                Log.e("ServiceHandler", "Couldn't get any data from the url");
            }

            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);
            // Dismiss the progress dialog
            if (pDialog != null) {
                pDialog.dismiss();
            }
            if (flag == 1) {
                Toast.makeText(WholesaleProductDetailActivity.this, msg, Toast.LENGTH_SHORT).show();
                quantity.setText("");
                cart.setText(cartNo);
                Pref.setValue(WholesaleProductDetailActivity.this, Const.PREF_CART_NO, cartNo);
            } else {
                Toast.makeText(WholesaleProductDetailActivity.this, msg, Toast.LENGTH_SHORT).show();
            }

        }
    }

}

4 个答案:

答案 0 :(得分:2)

用这个替换你的GetProductDetails AsyncTask代码。并为其他

做同样的事情
   // My AsyncTask start...
class GetProductDetails extends AsyncTask<Void, Void, Void> {
    private ProgressDialog pDialog;
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(WholesaleProductDetailActivity.this);
        pDialog.setMessage("Please wait...");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(false);
        pDialog.show();
    }

    @Override
    protected Void doInBackground(Void... arg0) {
         // Creating service handler class instance
        BackendAPIService sh = new BackendAPIService();
        // Making a request to url and getting response
        String jsonStr = sh.makeServiceCall(productUrl, BackendAPIService.GET);
        Log.d("Response: ", "> " + jsonStr);
        System.out.println("=============MY RESPONSE==========" + jsonStr);
        if (jsonStr != null) {
            try {
                JSONObject jsonObj = new JSONObject(jsonStr);
                // Getting JSON Array node
                if (jsonObj.has(Const.TAG_PRODUCT_DETAIL)) {
                    // yes
                    proDetails = jsonObj.getJSONArray(Const.TAG_PRODUCT_DETAIL);
                    System.out.println("==========inside doIn background===================");
                    // looping through All Contacts
                    for (int i = 0; i < proDetails.length(); i++) {
                        JSONObject c = proDetails.getJSONObject(i);
                        name = c.getString(Const.TAG_PRODUCT_NAME);
                        keywords = c.getString(Const.TAG_PRODUCT_KEYWORDS);
                        supplier_id = c.getString(Const.TAG_PRODUCT_SUPPLIER_ID);
                        supplier_name = c.getString(Const.TAG_PRODUCT_SUPPLIER_NAME);
                        listing_description = c.getString(Const.TAG_PRODUCT_LISTING_DESCRIPTION);
                        image = c.getString(Const.TAG_PRODUCT_IMG);
                        Specifications = c.getString(Const.TAG_PRODUCT_SPECIFICATION);
                        date_added = c.getString(Const.TAG_PRODUCT_DATE_ADDED);
                        customer_name = c.getString(Const.TAG_PRODUCT_CUSTMER_NAME);
                        customer_id = c.getString(Const.TAG_PRODUCT_CUSTOMER_ID);
                        retail_price = c.getString(Const.TAG_PRICE_RETAIL);
                        price_wholesale = c.getString(Const.TAG_PRICE_WHOLESALE);
                        System.out.println(":::::::::::::My wholesale price:::::::::>>>>>>>" + price_wholesale);
                        min_order_qty_retail = c.getString(Const.TAG_MIN_ORDER_QTY_RETAIL);
                        System.out.println(":::::::::::::My wholesale price:::::::::>>>>>>>" + min_order_qty_retail);
                        min_order_qty_wholesale = c.getString(Const.TAG_MIN_ORDER_QTY_WHOLESALE);
                        System.out.println(":::::::::::::My wholesale price:::::::::>>>>>>>" + min_order_qty_wholesale);
                        countyId = c.getString(Const.TAG_COUNTRY_ID);
                        state_id = c.getString(Const.TAG_STATE_WHOLESALE_ID);

                        supply_unit_id = c.getString(Const.TAG_PRODUCT_SUPPLEY_UNIT_ID);
                        supply_unit_name = c.getString(Const.TAG_PRODUCT_SUPPLY_UNIT_NAME);
                        System.out.println("::::::::::::::::mY supply unit name::::::::::::::");
                        supply_time = c.getString(Const.TAG_PRODUCT_SUPPLY_TIME);
                        delivery_time = c.getString(Const.TAG_DELIVERY_TIME_WHOLESALE);
                        System.out.println(":::::::::::::::supply unit name:::::::::::::::::::" + delivery_time);
                        company_name = c.getString(Const.TAG_PRODUCT_COMPANY_NAME);
                        System.out.println(":::::::::::::::supply unit name:::::::::::::::::::" + company_name);
                        // GETTING COMPANY DETAILS..........!!!
                        JSONObject companyDetails = c.getJSONObject(Const.TAG_PRODUCT_COMPANY_DETAILS);
                        companyDetailName = companyDetails.getString(Const.TAG_PRODUCTDETAIL_COMPANY_NAME);
                        companyDetailAddress = companyDetails.getString(Const.TAG_PRODUCTDETAIL_COMPANY_ADDRESS);
                        companyDetailMainProduct = companyDetails.getString(Const.TAG_PRODUCTDETAIL_COMPANY_MAIN_PRODUCT);
                        companyDetailotherProduct = companyDetails.getString(Const.TAG_PRODUCTDETAIL_COMPANY_OTHER_PRODUCT);
                        companyDetailPhoto = companyDetails.getString(Const.TAG_PRODUCTDETAIL_PHOTO);
                    }
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        } else {
            Log.e("ServiceHandler", "Couldn't get any data from the url");
        }
        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        super.onPostExecute(result);

        productName.setText(name);
        wholeSalePrice.setText("WholeSale Price:" + " " + price_wholesale);
        retailPrice.setText("Retail Price:" + " " + retail_price);
        tv_moqW.setText("MoqW:" + min_order_qty_wholesale);
        minOrder.setText("MoqR:" + min_order_qty_retail);
        shippingCost.setText("");
        escrowPayment.setText(payment_terms);
        compnyName.setText(company_name);
        countryName.setText(country_id);
        mainProduct.setText(companyDetailMainProduct);
        processingPeriod.setText(delivery_time);

        // Dismiss the progress dialog
        pDialog.dismiss();

    }
}
}

答案 1 :(得分:0)

删除

 if (pDialog.isShowing())

use  if (pDialog != null)

这可以帮到你

答案 2 :(得分:0)

您应该在执行super.onPostExecute(result);时删除onPostExecute(),因此您可能不希望框架处理它。

由于您已经在onPreExecute()中明确显示了进度对话框,因此您也可以省略isShowing()的检查,但我会建议您保持此检查,因为它不会造成任何伤害,并且几乎不会增加安全性。< / p>

答案 3 :(得分:0)

onPostExecute()区块中,您正在呼叫super.onPostExecute(result);

  @Override
  protected void onPostExecute(Void result) {
       super.onPostExecute(result);
            // Your code
  }

但是,当您覆盖onPostExecute()时,无需拨打super.onPostExecute(result);

如果你看一下AsyncTask source,你会发现超级课程什么也没做:

@SuppressWarnings({"UnusedDeclaration"})
protected void onPostExecute(Result result) {

}