Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 获取对小部件的引用,并在使用自定义XML布局创建的AlertDialog上设置其事件处理程序_Android_Events_Android Layout_Android Alertdialog - Fatal编程技术网

Android 获取对小部件的引用,并在使用自定义XML布局创建的AlertDialog上设置其事件处理程序

Android 获取对小部件的引用,并在使用自定义XML布局创建的AlertDialog上设置其事件处理程序,android,events,android-layout,android-alertdialog,Android,Events,Android Layout,Android Alertdialog,我使用LayoutInflater从布局创建了AlertDialog,它有一些按钮和一个gridview,并在我的活动类中重写了onCreateDialog,它在布局中打包并返回Dialog对象 在activity类的onCreate方法中,我使用showDialogid显示对话框,其中id是与特定对话框关联的常量 现在,我想将单击事件绑定到刚才显示的AlertDialog上的小部件。我的做法如下: showDialog(DLG_INPUT_FORM); inputform = new Dial

我使用LayoutInflater从布局创建了AlertDialog,它有一些按钮和一个gridview,并在我的活动类中重写了onCreateDialog,它在布局中打包并返回Dialog对象

在activity类的onCreate方法中,我使用showDialogid显示对话框,其中id是与特定对话框关联的常量

现在,我想将单击事件绑定到刚才显示的AlertDialog上的小部件。我的做法如下:

showDialog(DLG_INPUT_FORM);
inputform = new Dialog(MyActivity.this);
inputform.setContentView(R.layout.input_form);

edtName = (EditView) inputform.findViewById(R.id.edtName);
btnCheck = (Button) inputform.findViewById(R.id.btnCheck);
txtStatus = (TextView) inputform.findViewById(R.id.txtStatus);

//This event is never triggered.
btnCheck.setOnClickListener(new OnClickListener()
{
    public void onClick(View v)
    {
        String name = edtName.getText().toString();
        //Do Something with the "name"
        txtStatus.setText("Available");
    }
});
这不会引发任何异常,但单击按钮并没有任何作用,事实上事件根本不会被触发

代码中有什么错误

更新:


这个问题有点像,,我还获得了有关btnCheck和txtStatus对话框中的小部件的参考,但click event出现问题,它不起作用。

尝试将其更改为您的ClassName。这在代码的第二行,或者,代替showDialogID,在onCreate方法中弹出对话框,但我需要根据特定事件启动对话框,调用OnCreateDialogId而不是showDialog并使用返回的对象可以吗?如果可能,请在oncreate方法中处理事件,并根据条件显示对话框,而不使用onCreateDialog和showDialog,因为它们不工作。发布您在我们的onCreate对话框方法和show dialog方法中编写的内容。我尝试在onCreateDialog中绑定事件,但在尝试打开对话框时抛出了RuntimeException,因此我尝试在onCreate中执行此操作。