我有这段代码:
final AlertDialog.Builder alert = new AlertDialog.Builder(this);
final EditText name = new EditText(this);
final EditText surname = new EditText(this);
final EditText email = new EditText(this);
LinearLayout ll=new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
ll.addView(image);
ll.addView(name);
ll.addView(surname);
ll.addView(email);
alert.setView(ll);
alert.setPositiveButton(R.string.enter, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String name = // ??
String surname = // ??
String email = // ??
}
});
alert.show();
如何获取OnClickListener
内的EditText字段输入的文字字符串?
答案 0 :(得分:1)
试试这个
final AlertDialog.Builder alert = new AlertDialog.Builder(this);
final EditText name = new EditText(this);
final EditText surname = new EditText(this);
final EditText email = new EditText(this);
LinearLayout ll=new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
ll.addView(image);
ll.addView(name);
ll.addView(surname);
ll.addView(email);
alert.setView(ll);
alert.setPositiveButton(R.string.enter, new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String name_txt = name.getText().toString();
String surname_txt = surname.getText().toString();
String email_txt = email.getText().toString();
}
});
alert.show();