Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.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对话框警报_Android_Android Alertdialog_Toast - Fatal编程技术网

android对话框警报

android对话框警报,android,android-alertdialog,toast,Android,Android Alertdialog,Toast,我正在使用布局文件来显示对话框。我的xml文件是 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vert

我正在使用布局文件来显示对话框。我的xml文件是

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent" android:orientation="vertical">
    <EditText android:id="@+id/dialogEditText" android:text="Enter Your Text Here" android:layout_height="wrap_content" android:layout_width="match_parent"></EditText>
    <DatePicker android:id="@+id/datPicker" android:layout_height="wrap_content" android:layout_width="match_parent" ></DatePicker>
    <LinearLayout android:id="@+id/linearLayout1" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal">
     <Button android:text="Add" android:id="@+id/dialogAddBtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true"></Button>
     <Button android:text="Cancel" android:id="@+id/dialogCancelBtn" android:layout_width="200px" android:layout_height="wrap_content" android:layout_centerHorizontal="true"></Button>
    </LinearLayout>
</LinearLayout>
当我点击“确定”或“取消按钮”时,什么都没有发生。我无法理解为什么会发生这种情况。
请向我推荐一些解决方案。

您正在膨胀视图上设置事件处理程序,但同时将内容视图设置为普通布局:

window.setContentView(R.layout.dialog_view);
把这行改成

window.setContentView(inflatedView1);
或者,不使用布局充气器的更好方法是使用

d.setContentView(R.layout.dialog_view);
然后通过

Button okBtn = (Button) d.findViewById(R.id.dialogAddBtn);
okBtn.setOnClickListener(...

迈克尔

谢谢朋友,我非常感谢你。事实上,我对安卓系统还不熟悉。谢谢兄弟……嗯,我也是。D但是一旦你偶然发现了这些小事情,你就会记住它们;)
Button okBtn = (Button) d.findViewById(R.id.dialogAddBtn);
okBtn.setOnClickListener(...