У меня был настроенный диалог, и я поместил на него какую-то кнопку, XML-файл диалога выглядит так:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:layout_width="350sp"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="10dp" >
<FrameLayout
android:id="@+id/frameLayout4"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Confirm PSD"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/editText3"
android:layout_width="194dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:inputType="textPassword" />
</FrameLayout>
<FrameLayout
android:id="@+id/frameLayout5"
android:layout_width="254dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" >
<Button
android:id="@+id/button1"
android:layout_width="122dp"
android:layout_height="wrap_content"
android:text="OK"/>
<Button
android:id="@+id/button2"
android:layout_width="127dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="Cancel" />
</FrameLayout>
и это мой код:
Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.custom_dialog);
dialog.setTitle("Wify Setting");
dialog.show();
Отображается точно так же, как я хочу, но когда я устанавливаю свойство OnClick (имя метода) в button1, оно не работает, и приложение падает, даже если я использую findViewById (R.id.button1), чтобы найти кнопку и установите OnClickListener на него, он все равно не будет работать и вылетать.
Почему это?
спасибо за вашу помощь!
您 也 可以 用 中文 回答 我 謝謝