2014-09-29 79 views
-2

嗨在我的應用程序登錄表單與用戶名和密碼檢查數據庫中存在的用戶名和密碼或不。如果存在意味着顯示一個文本消息用戶找到,我想移動到下一個activity.otherwise沒有這樣的用戶找到。不移動到下一個活動

現在,點擊登錄按鈕,它顯示用戶找到並且沒有移動到下一個活動。

任何人都可以幫我解決這個問題。

Login.java

public class Login extends Activity { 
    Button login; 
    private static final Pattern USERNAME_PATTERN = Pattern 
      .compile("[a-zA-Z0-9]{1,250}"); 
    private static final Pattern PASSWORD_PATTERN = Pattern 
      .compile("[a-zA-Z0-9+_.]{4,16}"); 
    EditText usname,pword; 
    TextView tv; 

    String username,password; 
    HttpPost httppost; 
    StringBuffer buffer; 
    String data=""; 
    HttpResponse response; 
    HttpClient httpclient; 
    CheckBox mCbShowPwd; 
    List<NameValuePair> nameValuePairs; 
    ProgressDialog dialog = null; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.login); 

     login = (Button)findViewById(R.id.login); 
     usname = (EditText)findViewById(R.id.username); 
     pword= (EditText)findViewById(R.id.password); 
     tv = (TextView)findViewById(R.id.tv); 
     mCbShowPwd = (CheckBox) findViewById(R.id.cbShowPwd); 

     mCbShowPwd.setOnCheckedChangeListener(new OnCheckedChangeListener() { 

      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 

       if (!isChecked) { 

        pword.setTransformationMethod(PasswordTransformationMethod.getInstance()); 
       } else { 

        pword.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); 
       } 
      } 
     }); 

     login.setOnClickListener(new OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       String username = usname.getText().toString(); 
       String password = pword.getText().toString(); 
       if (username.equals("") || password.equals("")) { 
        if (username.equals("")) { 
         Toast.makeText(Login.this, "ENTER USERNAME", 
           Toast.LENGTH_LONG).show(); 

        } 
        if (password.equals("")) { 
         Toast.makeText(Login.this, "ENTER PASSWORD", 
           Toast.LENGTH_LONG).show(); 

        } 

       } else if (!CheckUsername(username) && !CheckPassword(password)){ 
         Toast.makeText(Login.this, "ENTER VALID USERNAME & PASSWORD", 
          Toast.LENGTH_LONG).show(); 
       } 
       else{ 
        final String queryString = "username=" + username + "&password=" 
        + password; 
        final String data = DatabaseUtility.executeQueryPhp("login",queryString); 

      System.out.println("data :: "+data); 
     tv.setText("Response from PHP : " + data); 
      if(data.equalsIgnoreCase("User Found")) 
      { 
       Toast.makeText(Login.this,"Login Success", Toast.LENGTH_SHORT).show(); 
       Intent i = new Intent(Login.this, Home.class); 
       startActivity(i);   
      } 
      else 
      { 
       Toast.makeText(getApplicationContext(),"User not found, check query", Toast.LENGTH_SHORT).show(); 
      } 
       }      

      } 
     }); 


    } 

      private boolean CheckPassword(String password) { 

       return PASSWORD_PATTERN.matcher(password).matches(); 
      } 

      private boolean CheckUsername(String username) { 

       return USERNAME_PATTERN.matcher(username).matches(); 
      } 

    } 
+0

您是否在AndroidManifest.xml中定義了Home活動? – 2014-09-29 08:41:21

+0

'Intent i = new Intent(Login.this,Home.class);'試一下。 – 2014-09-29 08:44:37

+0

有沒有在AndroidManifest.xml中添加 – user3436185 2014-09-29 08:49:34

回答

0

我認爲你缺少

<activity 
    android:name="package_name.Home"></activity> 

AndroidManifest.xml

您必須AndroidManifest.xml定義的所有活動。

編輯

System.out.println("data :: "+data); 
if(data.equalsIgnoreCase("User Found")) 
{ 
    Toast.makeText(getApplicationContext(),"Login Success", Toast.LENGTH_SHORT).show(); 
    Intent i = new Intent(getApplicationContext(), Home.class); 
    startActivity(i);   
} 
else 
{ 
    Toast.makeText(getApplicationContext(),"User not found, check query", Toast.LENGTH_SHORT).show(); 
} 
+0

嗨馬尼什我加Home.java清單中 – user3436185 2014-09-29 08:48:57

+0

@ user3436185你必須在添加問題logcat的細節。你能看到登錄成功的文本吐司? – 2014-09-29 09:03:05

+0

沒有Toast消息它沒有顯示 – user3436185 2014-09-29 09:07:30

0

我覺得你在這裏做的錯誤:

如果(data.equalsIgnoreCase( 「用戶找到」)){

      Toast.makeText(getApplicationContext(),"Login Success", Toast.LENGTH_SHORT).show(); 
          Intent i = new Intent(getApplicationContext(), Home.class); 

          startActivity(i);   

     } 

到位getApplicationContext的()寫入: if(data.equalsIgnoreCase(「User Found」)){

      Toast.makeText(Login.this,"Login Success", Toast.LENGTH_SHORT).show(); 
          Intent i = new Intent(getApplicationContext(), Home.class); 

          startActivity(i); 
相關問題