Android 对话框布局中缺少按钮

Android 对话框布局中缺少按钮,android,Android,有人知道为什么我的按钮没有出现在对话框窗口中吗 Dialog d = new Dialog(AddContact.this); LayoutInflater li = (LayoutInflater) getSystemService(Service.LAYOUT_INFLATER_SERVICE); ViewGroup contentView = (ViewGroup) li.inflate(R.layout.dialog,null); d.setConte

有人知道为什么我的按钮没有出现在对话框窗口中吗

    Dialog d = new Dialog(AddContact.this);

    LayoutInflater li = (LayoutInflater) getSystemService(Service.LAYOUT_INFLATER_SERVICE);
    ViewGroup contentView = (ViewGroup) li.inflate(R.layout.dialog,null);

    d.setContentView(contentView);
    d.setTitle("Please correct these errors:");

    TextView error = (TextView) contentView.findViewById(R.id.textView1);
    Button closer = (Button) contentView.findViewById(R.id.button1);

    closer.setText("Close");
    error.setText(errorMessage);
    d.show();
此my dialog.xml布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:orientation="vertical" android:padding="5dp">

    <TextView android:text="TextView" android:id="@+id/textView1"
        android:layout_height="fill_parent" android:layout_width="fill_parent" />

    <Button android:text="Button" android:id="@+id/button1"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:gravity="center" />

</LinearLayout>
<TextView android:text="TextView" android:id="@+id/textView1"
        android:layout_height="wrap_content" android:layout_width="fill_parent" />


我需要做什么才能使我的按钮显示在对话框窗口中?

您好,请尝试下面的代码

    Dialog d = new Dialog(AddContact.this);

    LayoutInflater li = (LayoutInflater) getSystemService(Service.LAYOUT_INFLATER_SERVICE);
    ViewGroup contentView = (ViewGroup) li.inflate(R.layout.dialog,null);

    d.setContentView(contentView);
    d.setTitle("Please correct these errors:");

    TextView error = (TextView) contentView.findViewById(R.id.textView1);
    Button closer = (Button) contentView.findViewById(R.id.button1);

    closer.setText("Close");
    error.setText(errorMessage);
    d.show();
仅替换dialog.xml布局文件中的Textview:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:orientation="vertical" android:padding="5dp">

    <TextView android:text="TextView" android:id="@+id/textView1"
        android:layout_height="fill_parent" android:layout_width="fill_parent" />

    <Button android:text="Button" android:id="@+id/button1"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:gravity="center" />

</LinearLayout>
<TextView android:text="TextView" android:id="@+id/textView1"
        android:layout_height="wrap_content" android:layout_width="fill_parent" />

您好,请尝试下面的代码

仅替换dialog.xml布局文件中的Textview:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:orientation="vertical" android:padding="5dp">

    <TextView android:text="TextView" android:id="@+id/textView1"
        android:layout_height="fill_parent" android:layout_width="fill_parent" />

    <Button android:text="Button" android:id="@+id/button1"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:gravity="center" />

</LinearLayout>
<TextView android:text="TextView" android:id="@+id/textView1"
        android:layout_height="wrap_content" android:layout_width="fill_parent" />


**强文本**

**强文本**

我缺少对话框上的按钮,原因是我向setButton发送了一个空字符串。

我缺少对话框上的按钮,原因是我向setButton发送了一个空字符串