0

我創建了一個簡單的登錄,用戶輸入他的詳細信息,並使用AsyncTask將用戶輸入與SQLite數據庫匹配,如果其正確,它將啓動主要活動的意圖。Android - 對話框解除

問題:

  1. 加載progressDialog犯規解僱如果用戶密碼/用戶名不正確,表示的是else語句敬酒時不正確的密碼/用戶名

在登錄類上的OnClick我有聲明的用戶輸入的新LoginTask這裏是我的AysncTask

private static class LoginTask extends AsyncTask<Void, Void, Boolean> { 

    ProgressDialog pd; 
    String username, password; 
    private final Context context; 
    Intent log; 
    // private final WeakReference<Context> reference; 

    private LoginTask(Context context, String username, String password) { 
     this.context = context; 
     this.username = username; 
     this.password = password; 

     //final Context context = this.context; 
     //Controller handler = new Controller(this.context); 

     pd = new ProgressDialog(this.context); 

    } 

    protected void onPreExecute() { 
     //super.onPreExecute(); 
     pd.show(this.context,"Authenticating account ...", "Please wait ..."); 
     pd.setCanceledOnTouchOutside(false); 

    } 

    @Override 
    protected Boolean doInBackground(Void... p) { 
     //final Context context = this.context; 
     Controller handler = new Controller(this.context); 
     handler.open(); 
     if (!handler.executeLog(username.trim(), password.trim())){ 
      return false; 
     } else { 
      return true; 

     } 
    } 

    @Override 
    protected void onPostExecute(Boolean result) { 
     pd.dismiss(); 
     // super.onPostExecute(result); 
     // final Context context = this.context; 
     Controller handler = new Controller(this.context); 
     handler.open(); 

      if (result == false) { 

       Toast.makeText(context, "Failed, Incorrect Username/Password", Toast.LENGTH_SHORT).show(); 

      } else { 
       handler.close(); 
       Intent log = new Intent(this.context, MainActivity.class); 
       context.startActivity(log); 
       ((Activity)context).finish(); 
       Toast.makeText(context, "You have successfully logged on, " + username, Toast.LENGTH_LONG).show(); 
      } 
     } 
    } 

}

+0

嗨,它可能更適合索要您的每一個問題,不同的問題,這樣你可以使用特定的代碼問的問題只有到每個問題。就目前而言,你的問題有點難以理解,也相當廣泛。 – 2015-03-03 13:38:12

+0

@Sippy我現在已經更新了它 – ExecuteCode 2015-03-03 13:39:40

+0

如果它處於同一活動中,則使用上下文或活動名稱替換您的this.context。 – 2015-03-03 14:17:20

回答

1

更改此:

protected void onPreExecute() { 
     //super.onPreExecute(); 
     pd.show(this.context,"Authenticating account ...", "Please wait ..."); 
     pd.setCanceledOnTouchOutside(false); 
} 

通過這樣的:

@Override 
protected void onPreExecute() { 
    // super.onPreExecute(); 
    this.pd.setCanceledOnTouchOutside(false); 
    this.pd.setCancelable(true); 
    this.pd.setTitle("Authenticating account ..."); 
    this.pd.setMessage("Please wait ..."); 
    this.pd.show(); 

}