2011-12-23 36 views
-1

我在Android應用程序中使用了ProgressDialog。 我有一個主要形式的登錄名,密碼和Loginbtn,當我登錄時,我移動到下一個屏幕,登錄是在互聯網和webdomain的基礎上,意味着登錄時發送請求到在線服務器有PHP文件,返回true或false,然後它移動到下一個屏幕。我想使用ProcessDialog,除非它從服務器獲得true或false,並且如果它變成false,那麼輪子應該停止處理,並且應該顯示消息:無效的用戶名或密碼,如果它變爲true,則在變爲true之後它應該結束處理對話框並移到下一個屏幕,現在ProcessDialog正在工作,但是當我們點擊時,我只是開始對話框工作,然後自動移動到下一個屏幕,但是如果我們按回按鈕,它仍然會顯示進程對話框旋轉。我只是想以正確的方式使用processDialog。 我的代碼是ProgressDialog無響應

//start 
progressDialog = new ProgressDialog(DomainDownManagerActivity.this); 
      progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); 
      progressDialog.setMessage("Loading..."); 
      progressDialog.show(); 
      progressDialog.setProgress(100); 

> if (v==true){ 
//v has true 
Intent intent = new Intent(DomainDownManagerActivity.this,MainPanelActivity.class); 

startActivity(intent); 

    } 

    else{ 
    //set label of invalid user or pass 
    } 

圖片連接 enter image description here

+0

誰在排行榜我負面的?如果你沒有答案,那麼不要評價負面的好! – 2011-12-23 12:50:14

+0

http://eagle.phys.utk.edu/guidry/android/progressBarExample.html – 2011-12-23 13:25:23

回答

1
// write this line `new SomeTask(0).execute();` in your loginBtn.onCLick 
/** Inner class for implementing progress bar before fetching data **/ 

    private class SomeTask extends AsyncTask<Void, Void, Integer> 
    { 
     private ProgressDialog Dialog = new ProgressDialog(yourActivityClass.this); 
     @Override 
     protected void onPreExecute() 
     { 

     Dialog.setMessage("loading..."); 
     Dialog.show(); 
    } 

    @Override 
    protected Integer doInBackground(Void... params) 
    { 


      //Task for doing something 
// get data from php server if true then return 

      return 0; 
    } 

    @Override 
    protected void onPostExecute(Integer result) 
     { 



     if(result==0) 
      { 
//do some thing if true 
Intent intent = new Intent(DomainDownManagerActivity.this,MainPanelActivity.class); 
startActivity(intent); 
      } 

    // after completed finished the progressbar 
      Dialog.dismiss(); 
     } 

    }