I have an app that I want to do the following:
- Show an activity with a button and TextView.
- User clicks on button and app shows a progress dialog.
- App calls a web service to get a list.
- Progress dialog is hidden and a List Selection dialog box appears to show the retrieved list.
- User selects one of the items in the list.
- Item shows in the TextView.
The problem is that this happens:
- Show an activity with a button and TextView.
- User clicks on button and button state changes to selected.
- A few seconds later, the List Selection dialog box appears to show the retrieved list.
- User selects one of the items in the list.
- Progress dialog shows for a few seconds, then is hidden.
- Item is shown in TextView.
The web service is executed in an AsyncTask with the progress dialog shown in the onPreExecute() method and dismissed in the onPostExecute() method:
public class WebService extends AsyncTask<Void, Void, Boolean> {
public void onPreExecute() {
_progressDialog = ProgressDialog.show(_context, "", message);
}
protected Boolean doInBackground(Void... params) {
try {
// Execute web service
}
catch (Exception e) {
e.printStackTrace();
}
return true;
}
protected void onPostExecute(Boolean result) {
_progressDialog.hide();
}
}
Code to execute web service and show dialog:
WebService ws= new WebService();
ws.execute();
// Web service saves retrieved list in local db
// Retrieve list from local db
AlertDialog.Builder db = new AlertDialog.Builder(context);
db.setTitle("Select an Item");
ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(context,
android.R.layout.simple_selectable_list_item, list);
db.setAdapter(listAdapter, null);
db.show();
Do I need to add something to the code to make sure the progress dialog shows before the List Selection dialog?
Thank you in advance.