我正在尝试创建自定义对话框。当我调用setOnClickListner
方法时,我得到了一个
“类型视图中的方法setOnClickListner不适用于参数。”我也在线上收到错误:
public void onClick(View v)
说“new onClickListener(){}的onClick(View)方法必须覆盖或实现超类型方法”。代码:
void ReStartsFamilyFriend()
{
// custom dialog
// custom dialog
final Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.gameover);
dialog.setTitle("Title...");
// set the custom dialog components - text, image and button
Button dialogButton = (Button) dialog.findViewById(R.id.butPlay);
// if button is clicked, close the custom dialog
//on this line below get the error "The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the arguments "
dialogButton.setOnClickListener(new OnClickListener() {
@Override
/*On the line below I get the error
"The method onClick(View) of type new OnClickListener(){} must override or implement a supertype
method"*/
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
答案 0 :(得分:0)
我觉得你要做的就是使用警告对话框中不同按钮之外的其他按钮来解除警报。您最好的选择是使用VVVVVVVVVVVVVVVVVV
dialog.setPositiveButton (CharSequence btnText, new DialogInterface.OnClickListener listener{
@Override
onClick(DialogInterface dialogInter, int whichBtn){
dialog.dismiss();
}
});
如果您使用alertDialog.builder,则无需在视图中放置按钮 查看link here