gpt4 book ai didi

java - 在警报对话框中访问 LinearLayout 中的 EditText

转载 作者:行者123 更新时间:2023-12-02 13:27:09 25 4
gpt4 key购买 nike

我有这个代码:

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 字段中输入的文本字符串?

最佳答案

试试这个

  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();

关于java - 在警报对话框中访问 LinearLayout 中的 EditText,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43348297/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com