我正在尝试在SurfaceView
上实现AlertDialog
,但出现此错误
error: incompatible types: <anonymous OnClickListener> cannot be converted to Callback
这就是我尝试过的
LayoutInflater inflater = getLayoutInflater();
View alertLayout = inflater.inflate(R.layout.popupdialog, null);
SurfaceView dialogsurface=(SurfaceView)alertLayout.findViewById(R.id.dialogcamerapreview);
surfaceHolder = dialogsurface.getHolder();
surfaceHolder.addCallback(this);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
AlertDialog.Builder alert = new AlertDialog.Builder(mContext);
alert.setTitle("Info");
alert.setView(alertLayout);
alert.setCancelable(false);
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getBaseContext(), "Cancel clicked", Toast.LENGTH_SHORT).show();
}
});
alert.setPositiveButton("Done", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(LoginActivity.this, "Photo captured..", Toast.LENGTH_SHORT).show();
}
});
AlertDialog dialog = alert.create();
dialog.show();
任何帮助将不胜感激
答案 0 :(得分:1)
使用此
surfaceHolder.addCallback(LoginActivity.this);
Toast.makeText(LoginActivity.this, "Cancel clicked", Toast.LENGTH_SHORT).show();
代替这个
surfaceHolder.addCallback(this);
Toast.makeText(getBaseContext(), "Cancel clicked", Toast.LENGTH_SHORT).show();