我在创建对话框时有时会报告此错误,我自己没有遇到过该错误,而且似乎每个用户都不会发生此错误,因为我正在通过对话框发送数据。我已经测试了 android 2.2。这是代码。
private static final int DIALOG_CONTEST_ENTRY = 939321;
showDialog(DIALOG_CONTEST_ENTRY);
protected Dialog onCreateDialog(int id) {
switch (id) {
case DIALOG_CONTEST_ENTRY:
final Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.contest_entry_dialog);
dialog.setTitle(getString(R.string.ContestEntryDialogTitle));
dialog.setCanceledOnTouchOutside(true);
TextView text = (TextView) dialog.findViewById(R.id.contest_text);
text.setText(getString(R.string.ContestEntryDialogText));
Button sendButton = (Button) dialog.findViewById(R.id.ButtonSend);
Button cancelButton = (Button) dialog.findViewById(R.id.ButtonCancel);
final EditText name = (EditText) dialog.findViewById(R.id.editName);
final EditText email = (EditText) dialog.findViewById(R.id.editEmail);
final TextView score = (TextView) dialog.findViewById(R.id.textScore);
final Prefs prefs = new Prefs(xxxActivity.this);
name.setText(prefs.ReadString("Name"));
email.setText(prefs.ReadString("Email"));
score.setText("Score: " + scoreCurrent);
sendButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//Send form
dialog.dismiss();
}
}
});
cancelButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
return dialog;
default:
break;
}
return super.onCreateDialog(id);
}
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" android:orientation="vertical" android:padding="10dp" android:background="#FFF">
<TextView
android:id="@+id/contest_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ContestEntryDialogText"
android:textColor="#000" />
<EditText
android:id="@+id/editName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName" android:hint="Enter Name"/>
<EditText
android:id="@+id/editEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress" android:hint="Enter Email">
<requestFocus />
</EditText>
<TextView
android:id="@+id/textScore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Score: " android:textSize="20dp"/>
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/ButtonSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send" />
<Button
android:id="@+id/ButtonCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel" />
</LinearLayout>