0

How to add a listview to my activity after the AsyncTask's onPostExecute() method? I'm preparing the listview items in doInBackground() method of AsyncTask.So,I want to add the listview after the AsyncTask is completed. Please help me to resolve this issue.

Thanks in Advance.

2 Answers2

1
protected void onPostExecute(Void result) {

            listview.setAdapter(dealAdapter);//Set your listview adapter Here

            if (progDialog.isShowing()) {
                progDialog.dismiss();
            }

        }
Aerrow
  • 12,086
  • 10
  • 56
  • 90
1

One more tip akka suggestion to optimize display process in Listview:

  1. As you are preparing data for listview inside doInBackground(), call publishProgress((yourData).

    // Here 'yourdata' can be either int or JSONObject or String or any.

  2. Once you call publishProgress(), it comes to the onProgressUpdate() method of AsyncTask, where you can add data in adapter and call notifyDatasetChanged() to notify the adapter about new data adding.

This way you can prepare data and publishing data one by one.

Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295