Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You are searching for AsyncTasks <a href="http://developer.android.com/reference/android/os/AsyncTask.html" rel="nofollow">http://developer.android.com/reference/android/os/AsyncTask.html</a></p> <p>It's pretty simple: You implement a class with AsyncTask as it's superclass and override the three methods:</p> <p>The <code>onPreExecute()</code>-method should show a <code>ProgressDialog</code></p> <p>The <code>doInBackground(Context... arg0)</code>-method collects the data from the database.</p> <p>The <code>onPostExecute(String result)</code>-method puts the data into the list and closes the <code>ProgressDialog</code></p> <p>In your code you should split your method into two: The first one (let's call it <code>getData()</code>) from the start to <code>db.close();</code> and everything after that in the second method (for example <code>showData()</code>)</p> <p>Then you create a class in your activity like this:</p> <pre><code>protected class LoadDataTask extends AsyncTask&lt;Context, Integer, String&gt; { ProgressDialog myLoadingDialog; @Override protected void onPreExecute() { myLoadingDialog = new ProgressDialog(YourActivity.this); myLoadingDialog.setMessage("Loading"); myLoadingDialog.setIndeterminate(false); myLoadingDialog.setCancelable(false); myLoadingDialog.show(); super.onPreExecute(); } @Override protected String doInBackground(Context... arg0) { getData(); return null; } @Override protected void onPostExecute(String result) { showData(); myLoadingDialog.dismiss(); super.onPostExecute(result); } } </code></pre> <p>Put the variables outside of the methods, which you need in both methods.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload