2015-10-19 64 views
0

我希望我的意圖僅在用戶通過登錄要求時才能通過。我試圖在onClick Listener中添加一條if語句,但它沒有解決。基本上,一旦用戶名和密碼符合我的要求,我想通過這個意圖。如果意圖沒有通過,那麼我想傳遞一個else語句,表示「該用戶不存在」。我想讓用戶通過我的登錄要求,以便登錄

10-20 16:53:10.330 2138-2138/com.squarespace.atpublishing.officialworkoutapp 

I/art: Not late-enabling -Xcheck:jni (already on) 
10-20 16:53:11.510 2138-2145/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 220ms 
10-20 16:53:11.640 2138-2150/com.squarespace.atpublishing.officialworkoutapp I/art: Background sticky concurrent mark sweep GC freed 1555(94KB) AllocSpace objects, 0(0B) LOS objects, 33% free, 417KB/623KB, paused 0 total 130ms 
10-20 16:53:11.850 2138-2138/com.squarespace.atpublishing.officialworkoutapp W/art: Verification of boolean android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.onCreatePanelMenu(int, android.view.Menu) took 170ms 
10-20 16:53:11.850 2138-2145/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 130ms 
10-20 16:53:12.780 2138-2145/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 80ms 
10-20 16:53:13.660 2138-2145/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 30ms 
10-20 16:53:13.900 2138-2150/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 10ms 
10-20 16:53:13.900 2138-2150/com.squarespace.atpublishing.officialworkoutapp I/art: Background sticky concurrent mark sweep GC freed 1031(117KB) AllocSpace objects, 0(0B) LOS objects, 23% free, 781KB/1017KB, paused 10ms total 60ms 
10-20 16:53:14.340 2138-2150/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 10ms 
10-20 16:53:14.340 2138-2150/com.squarespace.atpublishing.officialworkoutapp I/art: Background sticky concurrent mark sweep GC freed 282(24KB) AllocSpace objects, 0(0B) LOS objects, 13% free, 878KB/1017KB, paused 10ms total 80ms 
10-20 16:53:14.460 2138-2150/com.squarespace.atpublishing.officialworkoutapp I/art: Background partial concurrent mark sweep GC freed 297(33KB) AllocSpace objects, 0(0B) LOS objects, 36% free, 885KB/1397KB, paused 0 total 120ms 
10-20 16:53:14.630 2138-2145/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 20ms 
10-20 16:53:14.900 2138-2229/com.squarespace.atpublishing.officialworkoutapp D/OpenGLRenderer: Render dirty regions requested: true 
10-20 16:53:14.950 2138-2138/com.squarespace.atpublishing.officialworkoutapp D/: HostConnection::get() New Host Connection established 0x7fb36d6b8620, tid 2138 
10-20 16:53:14.960 2138-2138/com.squarespace.atpublishing.officialworkoutapp D/Atlas: Validating map... 
10-20 16:53:15.260 2138-2229/com.squarespace.atpublishing.officialworkoutapp D/: HostConnection::get() New Host Connection established 0x7fb36d6ec100, tid 2229 
10-20 16:53:15.350 2138-2229/com.squarespace.atpublishing.officialworkoutapp I/OpenGLRenderer: Initialized EGL, version 1.4 
10-20 16:53:15.430 2138-2229/com.squarespace.atpublishing.officialworkoutapp D/OpenGLRenderer: Enabling debug mode 0 
10-20 16:53:15.440 2138-2229/com.squarespace.atpublishing.officialworkoutapp W/EGL_emulation: eglSurfaceAttrib not implemented 
10-20 16:53:15.440 2138-2229/com.squarespace.atpublishing.officialworkoutapp W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7fb36d6b7b00, error=EGL_SUCCESS 
10-20 16:53:15.620 2138-2145/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 30ms 
10-20 16:53:15.650 2138-2138/com.squarespace.atpublishing.officialworkoutapp I/Choreographer: Skipped 39 frames! The application may be doing too much work on its main thread. 
10-20 16:53:20.900 2138-2145/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 40ms 
10-20 16:53:20.930 2138-2150/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 20ms 
10-20 16:53:21.510 2138-2145/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 190ms 
10-20 16:53:21.660 2138-2138/com.squarespace.atpublishing.officialworkoutapp I/Choreographer: Skipped 102 frames! The application may be doing too much work on its main thread. 
10-20 12:53:24.100 2138-2150/com.squarespace.atpublishing.officialworkoutapp I/art: Background sticky concurrent mark sweep GC freed 278(36KB) AllocSpace objects, 0(0B) LOS objects, 11% free, 1242KB/1397KB, paused 0 total 190ms 
10-20 12:53:25.100 2138-2145/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 70ms 
10-20 12:53:26.510 2138-2145/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 30ms 
10-20 12:53:27.000 2138-2145/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 20ms 
10-20 12:53:27.330 2138-2138/com.squarespace.atpublishing.officialworkoutapp I/Choreographer: Skipped 149 frames! The application may be doing too much work on its main thread. 
10-20 12:53:27.770 2138-2229/com.squarespace.atpublishing.officialworkoutapp W/EGL_emulation: eglSurfaceAttrib not implemented 
10-20 12:53:27.770 2138-2229/com.squarespace.atpublishing.officialworkoutapp W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7fb36d2e6900, error=EGL_SUCCESS 
10-20 12:53:28.120 2138-2138/com.squarespace.atpublishing.officialworkoutapp I/Choreographer: Skipped 47 frames! The application may be doing too much work on its main thread. 
10-20 12:53:28.220 2138-2229/com.squarespace.atpublishing.officialworkoutapp W/EGL_emulation: eglSurfaceAttrib not implemented 
10-20 12:53:28.220 2138-2229/com.squarespace.atpublishing.officialworkoutapp W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7fb36d2e69c0, error=EGL_SUCCESS 
10-20 12:53:28.270 2138-2138/com.squarespace.atpublishing.officialworkoutapp W/View: requestLayout() improperly called by android.support.design.internal.NavigationMenuView{2c5956e4 VFED.VC. ......ID 0,0-384,800} during layout: running second layout pass 
10-20 12:53:28.460 2138-2145/com.squarespace.atpublishing.officialworkoutapp W/art: Suspending all threads took: 20ms 
10-20 12:53:29.040 2138-2138/com.squarespace.atpublishing.officialworkoutapp I/Choreographer: Skipped 38 frames! The application may be doing too much work on its main thread. 

`

 Button mEmailSignInButton = (Button)  
     findViewById(R.id.email_sign_in_button); 

     mEmailSignInButton.setOnClickListener(new OnClickListener() { 

     @Override 


     public void onClick(View view) { 

     attemptLogin(); 


if (mPasswordView.getText().toString().isEmpty() && mEmailSignInButton.getText().toString().isEmpty()){ 
       Snackbar.make(view, "You Didn't enter anything", Snackbar.LENGTH_LONG).setAction("Action", null); 
      } else { 
       Intent intent = new Intent(LoginActivity.this, DrawerActivity.class); 
       startActivity(intent); 
      } 

      Intent intent = new Intent(LoginActivity.this,  DrawerActivity.class); 
      startActivity(intent); 
     } 
    });  


/** 
* Attempts to sign in or register the account specified by the login form. 
* If there are form errors (invalid email, missing fields, etc.), the 
* errors are presented and no actual login attempt is made. 
*/ 
private void attemptLogin() { 
    if (mAuthTask != null) { 
     return; 
    } 

    // Reset errors. 
    mEmailView.setError(null); 
    mPasswordView.setError(null); 

    // Store values at the time of the login attempt. 
    String email = mEmailView.getText().toString(); 
    String password = mPasswordView.getText().toString(); 

    boolean cancel = false; 
    View focusView = null; 

    // Check for a valid password, if the user entered one. 
    if (!TextUtils.isEmpty(password) && !isPasswordValid(password)) { 
     mPasswordView.setError(getString(R.string.error_invalid_password)); 
     focusView = mPasswordView; 
     cancel = true; 
    } 

    // Check for a valid email address. 
    if (TextUtils.isEmpty(email)) { 
     mEmailView.setError(getString(R.string.error_field_required)); 
     focusView = mEmailView; 
     cancel = true; 
    } else if (!isEmailValid(email)) { 
     mEmailView.setError(getString(R.string.error_invalid_email)); 
     focusView = mEmailView; 
     cancel = true; 
    } 

    if (cancel) { 
     // There was an error; don't attempt login and focus the first 
     // form field with an error. 
     focusView.requestFocus(); 
    } else { 
     // Show a progress spinner, and kick off a background task to 
     // perform the user login attempt. 
     showProgress(true); 
     mAuthTask = new UserLoginTask(email, password); 
     mAuthTask.execute((Void) null) 

    } 
} 
+0

什麼「沒有工作」?重新介紹一下沒有解決的原始代碼,將其發佈到這裏,然後向我們展示logcat。我們不是在這裏爲你寫代碼。我們在這裏糾正你,讓你可以從自己的錯誤中學習(並希望不再需要我們的幫助)。如果你隱瞞你的錯誤,那是無法學習的。 –

+0

我明白了。我的錯。我只是在點擊監聽器下放了我的logcat和if else語句。 – theJavaGuy

+0

我仍然有一些問題,但我會研究它。我只練了3-4周的Java,所以請原諒我的錯誤。我會查看該網站並繼續練習。謝謝您的幫助 – theJavaGuy

回答

0

attemptLogin();需求,如果你的其他{}內調用。

目前,它在您的if之前被調用,所以即使您的電子郵件或密碼字段爲空,它也會嘗試登錄。

這可能只是您的一個疏忽。如果沒有,您可能想通過在以下網站上進行練習來刷新Java。 http://codingbat.com/java