2012-02-05 3 views
0
public void createpass() { 
//set up dialog 
final Dialog dialog = new Dialog(App.this); 
dialog.setContentView(R.layout.createpass); 
dialog.setTitle("Set Password"); 
dialog.setCancelable(false); 
//there are a lot of settings, for dialog, check them all out! 

//set up text 
final EditText text = (EditText) dialog.findViewById(R.id.editText1); 
text.setText(""); 
//set up text 
final EditText text2 = (EditText) dialog.findViewById(R.id.editText2); 
text2.setText(""); 



//set up button 
Button button = (Button) dialog.findViewById(R.id.Button01); 
button.setOnClickListener(new OnClickListener() { 
@Override 
    public void onClick(View v) { 

    String createpass_password = text.getText().toString().trim(); 
    String createpass_password2 = text2.getText().toString().trim(); 


    try 
    { 
     if(createpass_password == createpass_password2) 
     { 
      FileWriter fstream = new FileWriter("/data/data/folder.hide.alexander.fuchs/password.db"); 
      BufferedWriter out = new BufferedWriter(fstream); 
      out.write(createpass_password); 
      //Close the output stream 
      out.close();  
     dialog.dismiss(); 
     } 
     else 
     { 
      toaster("Passwords are not matching !"); 
      text.setText(""); 
      text2.setText(""); 
     } 
    } 
    catch(Exception x) 
    {  
     String ErrorMessage = x.getMessage(); 
     toaster("Error"); 
     finish(); 
    } 

} 
}); 
//now that the dialog is set up, it's time to show it 

    dialog.show(); 

} 

Я пытаюсь получить доступ к значению EditText, они должны быть равны , но они не являютсяAndroid Пользовательского Dialog EditText

Я пытаюсь сделать диалог пароля и пароль проверяется проверить с помощью «если еще»

диалоговое окно отображается корректно, но когда я ввести то же значение если структура сообщает о них не равны

ответ

3

Вы должны использовать "String".equals("String") для тестирования содержимого String.

== проверяет, соответствуют ли ссылки на объекты.

Так что в вашем коде, вы должны сделать:

if (createpass_password.equals(createpass_password2)) {