How to get values in android AlertDialog[ RESOLVED ]

It's simple.. look this code:

private void openDialogLogin(){

LayoutInflater factory = LayoutInflater.from(Jira3Layer.this);

final View textEntryView = factory.inflate(R.layout.alert_dialog_text_entry, null);

AlertDialog.Builder loginPopup = new AlertDialog.Builder(Jira3Layer.this);

loginPopup.setTitle("Login")

.setView(textEntryView)

.setPositiveButton(R.string.login,new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int whichButton) {

// HERE IS THE GREATE SOLUTION FOR ALERTDIALOG VALUES.

EditText username = (EditText) textEntryView.findViewById(R.id.username_edit);

EditText password = (EditText) textEntryView.findViewById(R.id.password_edit);

Toast.makeText(YourClass.this, "Values: "+username.getText()+" "+password.getText(), Toast.LENGTH_SHORT).show();


}

})

.setNegativeButton(R.string.calcel,

new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int whichButton) {

dialog.dismiss();

Toast.makeText(Jira3Layer.this,"open login", Toast.LENGTH_SHORT).show();


}

}).show();

}

2 comentários: