如何从Custom AlertDialog中的textedit检索文本

时间:2011-11-15 18:31:13

标签: android

尝试以下操作会导致错误。如何从自定义alertdialog中检索用户输入的值?我做了一个setText来测试这种方式是否有效。

这是我的代码:

View categoryDetailView = View.inflate(this, R.layout.customdialoghotspot, null);

final AlertDialog.Builder b = new AlertDialog.Builder(this);

b.setView(categoryDetailView);
b.setTitle("Add Current Location");
b.setPositiveButton("OK",null);
b.setNegativeButton("Cancel",null);

b.show();

1 个答案:

答案 0 :(得分:0)

没关系找到答案

    View categoryDetailView = View.inflate(this, R.layout.customdialoghotspot, null);

    final AlertDialog.Builder b = new AlertDialog.Builder(this);

    b.setView(categoryDetailView);
    b.setTitle("Add Current Location");
    b.setPositiveButton("OK",null);
    b.setNegativeButton("Cancel",null);

  AlertDialog a=  b.show();

    EditText editTextMemberName = (EditText)a.findViewById(R.id.txtNewText);
    editTextMemberName.setText("test");