我从sdk版本我正匆忙地收到这个错误报告。我无法直接测试,因为我没有sdkjava.lang.IllegalargumentException,android.app.activity.createDialog:880-(activity oncreateDialog没有为ID 1创建对话框)
下面是我实现的oncreatedialog(int id)。
@Override
protected Dialog onCreateDialog(int id) {
super.onCreateDialog(id);
Dialog dialog = null;
switch(id){
case 1:
dialog = new CustomCalcDialog(this);
dialog.setTitle("Enter Shipping %");
activeTextView = shippingPercent;
dialog.show();
dialog = null;
break;
case 2:
dialog = new CustomCalcDialog(this);
dialog.setTitle("Enter Tax Rate");
activeTextView = taxPercent;
dialog.show();
dialog = null;
break;
case 3:
dialog = new CustomCalcDialog(this);
dialog.setTitle("Enter Commission %");
activeTextView = commissionPercent;
dialog.show();
dialog = null;
break;
case 4:
dialog = new CustomCalcDialog(this);
dialog.setTitle("Calculate Subtotal");
activeTextView = productSubtotal;
dialog.show();
dialog = null;
break;
case 5:
dialog = new CustomCalcDialog(this);
dialog.setTitle("Additional Shipping");
activeTextView = addShipping;
dialog.show();
dialog = null;
break;
case 6:
dialog = new BackgroundOptionsDialog(this);
dialog.setTitle("Choose Background:");
dialog.show();
dialog = null;
break;
default:
dialog = null;
}
return dialog;
}
下面是如何取消对话。
private void registerListeners () {
enterTotal.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
calcLogic(EQUALS);
}catch(Exception ex){}
operatorChange = DONT_CHANGE;
activeTextView.setText(calcDialogDisplay.getText().toString());
try {
if ((Float.parseFloat(calcDialogDisplay.getText().toString())) < 0) {}
}catch(Exception ex) {
activeTextView.setText("0");
}
mathCalculations();
CustomCalcDialog.this.dismiss();
}
});
最佳答案
也有问题,并用以下方法解决:
-在方法中不返回空对话框:protected dialog oncreatedialog(in t id)
在activity.java中的android 2.1中,错误出现在第871行。
private Dialog createDialog(Integer dialogId, Bundle state) {
869 final Dialog dialog = onCreateDialog(dialogId);
870 if (dialog == null) {
871 throw new IllegalArgumentException("Activity#onCreateDialog did "
872 + "not create a dialog for id " + dialogId);
873 }
874 dialog.dispatchOnCreate(state);
875 return dialog;
876 }
如果您稍后在android中查看,会检查一个空对话框,并返回handeld。所以在这里它起作用了。
-不使用bundle(在API8中更改):
受保护的对话框oncreatedialog(int id,bundle bundle);
用途:
受保护的对话oncreatedialog(int id);
-我还使用了以下检查(有一个带有自定义对话框的特例):
if(Build.VERSION.SDK_INT <= Build.VERSION_CODES.ECLAIR_MR1) {
return dialog;
} else {
return null;
}
也许它能帮助某人…