Panache
Panache

Reputation: 1721

Mandatory Progress bar while fetching & showing data in listview

I am using below code to show progress bar when user clicks to get list of apps in mobile. Issue is this bar hardly appears, where as I noted it take 2 to 3 seconds to show the list of apps in activity.

 static private void prod() {
        progressDialog = new ProgressDialog(activity);
        progressDialog.setCancelable(false);
        progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        progressDialog.setTitle("Fetching App List");
        progressDialog.setMessage("Please Wait...");
        progressDialog.show();

    }

This is how I passing data to custom listview.

  Adapter = new AppListAdapter(context, packageList, packageManager);
        apps.setAdapter(Adapter);

and here I m calling progress dismiss like this in getView of Adapter class.

 AppList.procan();
        return convertView;

Does 2 to 3 second not sufficient to at least show progress bar.

I m calling this method on click and dismissing on when listview adapter is called.

I saw in many applications even for 1 sec of application show progress bar. Why not I could able to get. What fix can I do.?

Upvotes: 2

Views: 478

Answers (1)

Pavneet_Singh
Pavneet_Singh

Reputation: 37404

The issue could be initialization(time consuming) of ProgressDialog during every click so

1.) make method non-static and initialize the progressDialog in oncreate (or initialize it ASAP if it's in different class)

2.) Then only call show on the instance of progressDialog

ProgressDialog progressDialog;;
protected void onCreate(...) {
   //...code
    progressDialog = new ProgressDialog(activity);
    progressDialog.setCancelable(false);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    progressDialog.setTitle("Fetching App List");
    progressDialog.setMessage("Please Wait...");

}

private void prod() {
    progressDialog.show();
}

Upvotes: 2

Related Questions