Progress dialog dismisses before the view is displayed in the gridview
<p>I start my progress dialog in oncreate method of fragment before is initiate my web request call. In the web request call, if I fetch the response and if its success I call the <code>notifydatasetchanged</code> method to refresh the adapter . But the dialog gets dismissed lot before the view is updated . Please help . </p>

<pre><code>@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


    pd = ProgressDialog.show(getActivity(), "Loading...", "Please Wait...");
    getProducts(highPrice, lowPrice, isLowtoHigh);
}


 private void getProducts(String highPrice,String lowPrice,String isLowtoHigh) {

   // loadingDialog.loading();

    APIRequst.getProductsCategory(getActivity().getApplicationContext(), isLowtoHigh, lowPrice, highPrice, new APIRequestListner() {
        @Override
        public void onSuccess(String response) {

            if (response == null || response.isEmpty()) {
                Log.e("orderhistory", "success but empty");
            } else {
                Log.e("products", response);
                try {
                    JSONObject mainObj = new JSONObject(response);
                    boolean result = mainObj.has("is_success") &amp;&amp; mainObj.getBoolean("is_success");

                    String resultMessage = mainObj.getString("message");
                    if (resultMessage.equalsIgnoreCase("Success")) {

                        if (result) {


                            productItems.clear();
                            adptProductItems.clear();
                            JSONArray jsonOrderList = mainObj.has("categories") ? mainObj.getJSONArray("categories") : null;
                            if (jsonOrderList != null) {
                                for (int i = 0; i &lt; jsonOrderList.length(); i++) {
                                    JSONObject jsonObj = jsonOrderList.getJSONObject(i);
                                    ProductListItem newItem = (new Gson()).fromJson(jsonObj.toString(), ProductListItem.class);
                                    productItems.add(newItem);
                                }

                                adptProductItems.notifyDataSetChanged();
                                pd.dismiss();
                            }
                        }
                    } else {

                        if (resultMessage.equalsIgnoreCase("No Value")) {

                            if (pd.isShowing())
                                pd.dismiss();
                            productItems.clear();
                            adptProductItems.notifyDataSetChanged();

                            Toast.makeText(getActivity(), "Sorry no prducts to display", Toast.LENGTH_SHORT).show();
                        }

                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            // adapter.notifyDataSetChanged();
        }

        @Override
        public void onFailure() {
            if (pd.isShowing())
                pd.dismiss();
            //  loadingDialog.dismissDialog();
        }
    });
}
</code></pre>