2011-01-29 3 views
0

로그인 애플리케이션을 만들었습니다. 그러나 잘못된 암호를 입력하면 앱에 암호가 잘못되었다는 알림이 표시되지 않으며 코드를 입력하지 않았기 때문에 앱에 아무런 알림도 표시되지 않습니다. 나는 그것을 성취하기 위해 무엇을 써야할지 모른다. 나는 여기 초보자이다. 도와주세요. Toast notification을 보여비밀번호 확인 도움말

if(passwordEditText.getText().toString().equals(password)) //checking if they put the right password? 
    { 
     StartMain(); //I assume this is starting the application 
    } 
else 
{ 
    //Tell them the password was wrong. 
} 

답변

1

간단한 생각은 다음과 같습니다 당신은 아마 당신의 내면의 if 문에 다른 조건을 원하는

public void onClick(View v) 
{ 
    EditText passwordEditText = (EditText) findViewById(R.id.currentPass); 
    SharedPreferences prefs = this.getApplicationContext().getSharedPreferences("prefs_file",MODE_PRIVATE); 
    String password = prefs.getString("password",""); 
    if("".equals(password)) 
    { 
     Editor edit = prefs.edit(); 
     edit.putString("password",passwordEditText.getText().toString()); 
     edit.commit(); 
     StartMain(); 
    } 
    else 
    { 
    if(passwordEditText.getText().toString().equals(password)) 
     { 
      StartMain(); 
     } 
    } 

} 
+0

penov : 고마워요! – sean

2

:

이 내 코드입니다. 위의 코드에서 두 번째 (중첩 된) ifelse 분기에서이를 수행 할 수 있습니다.

+0

해밍 : 감사합니다. – sean

0

안녕하세요 schadi : 내가 문제라고 생각합니다. EditText는 클릭 이벤트를 먼저 잡아서 password.so를 입력해야합니다. 코드는 항상 "" ".equals (password) '진술. TextWatcher 등을 사용하여 작업을 할 수 있습니다.

중국어 사람, 영어 가난, 난 당신이 내가 말하고 무엇을 : 나는 사용자에게 알리기 위해 축배를 사용하는 것이 좋습니다

0

이해할 수 있기를 바랍니다. 이와 같이 :

else 
    { 
    if(passwordEditText.getText().toString().equals(password)) 
     { 
      StartMain(); 
     } 
    } else { 
    Toast.makeText(v.getContext(), "Wrong password!", Toast.LENGTH_LONG).show(); 
}