android - Progress dialog shows too late -


i have app want following:

  1. show activity button , textview.
  2. user clicks on button , app shows progress dialog.
  3. app calls web service list.
  4. progress dialog hidden , list selection dialog box appears show retrieved list.
  5. user selects 1 of items in list.
  6. item shows in textview.

the problem happens:

  1. show activity button , textview.
  2. user clicks on button , button state changes selected.
  3. a few seconds later, list selection dialog box appears show retrieved list.
  4. user selects 1 of items in list.
  5. progress dialog shows few seconds, hidden.
  6. item shown in textview.

the web service executed in asynctask progress dialog shown in onpreexecute() method , dismissed in 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 execute web service , show dialog:

webservice ws= new webservice(); ws.execute();  // web service saves retrieved list in local db  // retrieve list local db  alertdialog.builder db = new alertdialog.builder(context); db.settitle("select item"); arrayadapter<string> listadapter = new arrayadapter<string>(context,         android.r.layout.simple_selectable_list_item, list); db.setadapter(listadapter, null); db.show(); 

do need add code make sure progress dialog shows before list selection dialog?

thank in advance.

here's how it:

public onclicklistener loginlistener = new onclicklistener() {     public void onclick(view v) {         progressdialog progressdialog = new progressdialog(activity);         progressdialog.setmessage("logging in...");         logintask logintask = new logintask(activity, progressdialog, loginlayout, loggedinlayout);         logintask.execute();     } }; 

the asynctask:

protected void onpreexecute() {     progressdialog.show(); }  protected void onpostexecute(integer responsecode) { if (responsecode == 1) {         progressdialog.dismiss();         int duration = toast.length_short;         toast toast = toast.maketext(activity.getapplicationcontext(), "logged in.", duration);         toast.show();         activity.bar.gettabat(0).settext(dbhandler.getuserdetails().get("email")); 

so, create progressdialog in main activity set message before declare/execute task. then, task shows , dismisses (not hide) dialog.

let me know if works!


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -