title: Android: Loading a listview from a database after populating it asynchronously
body: <p>I'm trying to show a progress dialog while loading information from the web that populates an sqlite database from which a Listview is created. I created an async class that displays a progress dialog box while the information is downloaded but after that the listview is empty. That is probably because the listview is already loaded before async. So how do I reload the listview or do this the right way? Here is what I have so far (left out the background processing since it's too long to displag):</p>
  
  <pre><code>private class DownloadInfo extends AsyncTask &lt;Void, Void, Void&gt;{
      //////////////////Open Dialog before execution ///////////
  private ProgressDialog dialog;
      protected void onPreExecute(){
          dialog = new ProgressDialog(CandidatesList.this);
          dialog.setMessage("Loading Candidates from Webserver");
          dialog.setIndeterminate(true);
          dialog.setCancelable(false);
          dialog.show();
      }
      ///////////////Background Processing//////////////////
      @Override
      protected Void doInBackground(Void... dbArray) {
      ////Load information from webserver and put it in sqlite///
          return null;
  
      }
  
      ///////After the processing is done //////////////
      protected void onPostExecute(Void unused) {
          dialog.dismiss();
      }
  
  }
  </code></pre>
  
  <p>And the on create is as follows:</p>
  
  <pre><code>DownloadInfo task = new DownloadInfo();
      task.execute();
  Cursor c = db.getAllCandidates();
      candidates = new String[c.getCount()];
      if (c.moveToFirst()) {
          int i = 0;
          do {
              candidates[i] = c.getString(1);// insert Name into candidate
                                              // Array
              i++;
          } while (c.moveToNext());
      }
      setListAdapter(new ArrayAdapter&lt;String&gt;(this, R.layout.list_item,
              candidates));
  </code></pre>
  
  <p>Please help,
  Thank you</p>