我的同事之前关于某个警报对话框的源代码是
this.mProgressDialog = new ProgressDialog()
{
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
SimLog.d(TAG, "onKeyDown()[back:4]=" + keyCode);
if (keyCode == KeyEvent.KEYCODE_BACK) {
dismiss();
doCancelImport();
finish();
return true;
}
return super.onKeyDown(keyCode, event);
}
};
要对此对话框进行一些修改,我必须将此代码更改为:
this.mProgressDialog = mBuilder.create();
this.mProgressDialog.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
SimLog.d(TAG, "onKeyDown()[back:4]=" + keyCode);
if (keyCode == KeyEvent.KEYCODE_BACK) {
dismiss();
doCancelImport();
finish();
return true;
}
return super.onKey(keyCode, event);
}
});
但我的日食显示错误:
"类型Dialog中的方法setOnKeyListener(DialogInterface.OnKeyListener)不适用于参数(new OnKeyListener())"
为什么这不起作用?我该怎么修改呢?