Итак, у меня есть диалоговое окно, которое означает принятие имени пользователя и пароля, но когда я пытаюсь получить имя пользователя и пароль от объекта EditText
, я не могу получить объект EditText
отресурсы, мой код выглядит следующим образом.
protected Dialog onCreateDialog(int ID){
LayoutInflater factory = LayoutInflater.from(this);
final View textEntryView = factory.inflate(R.layout.login_dialogue, null);
return new AlertDialog.Builder(this)
.setTitle("Login:")
.setView(textEntryView)
.setPositiveButton("login", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/* Problem occurs below */
View aView = findViewById(R.id.login_dialogue_username);
String username = ((EditText) aView).getText().toString();
String password = ((TextView) findViewById(R.id.login_dialogue_password)).getText().toString();
boolean success = attemptLogin(username, password);
}
})
.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked cancel so do some stuff */
}
})
.create();
}
Поэтому, когда я перехожу к отладке, переменная aView
равна нулю, но я не понимаю, почему.Ресурс находится в моем файле R
и в затмении он окрашен в синий цвет, что указывает на то, что он соответствует имени в файле R.Кто-нибудь знает, что здесь происходит?