试图将我的应用程序从 android 2.2 (API 8) 降级到 android 2.1 (API7),我遇到了一些对话框问题。基于这个线程,我试图捕捉这些异常但不能覆盖 showDialog 方法。
我根据这个对类似问题的回答将 Java 编译器从 1.5 转换为 1.6,但没有任何变化,Eclipse 仍然返回:
无法从 Activity 覆盖 final 方法
public class MyActivity extends Activity implements
SeekBar.OnSeekBarChangeListener {
// ... some stuffs
@Override // here is the issue
public void showDialog(int dialogId) {
try {
super.showDialog(dialogId);
} catch (IllegalArgumentException e) {
Log.e(ACTIVITY_TAG, "Error dialog");
}
}
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DIALOG_ALERT:
// Create out AlertDialog
Builder builder = new AlertDialog.Builder(this);
builder.setMessage(msg);
builder.setCancelable(false);
builder.setPositiveButton(GOTO_BOOK, new OkOnClickListener());
builder.setNegativeButton(STAY_HERE, new CancelOnClickListener());
AlertDialog dialog = builder.create();
dialog.show();
break;
case DIALOG_ONCREATE:
// Create out AlertDialog during the "onCreate" method (only "Ok"
// button)
Builder builder2 = new AlertDialog.Builder(getParent());
builder2.setMessage(msg);
builder2.setCancelable(false);
builder2.setPositiveButton(GO_BACK, new OkOnClickListener());
AlertDialog dialog2 = builder2.create();
dialog2.show();
break;
}
return super.onCreateDialog(id);
}
// ... some stuffs
}