[英]Android: trying to create a custom dialog
I'm trying to create a custom dialog. 我正在尝试创建一个自定义对话框。 When I call the
setOnClickListner
method I get a "the method setOnClickListner in the type view is not applicable for arguments." 当我调用
setOnClickListner
方法时,出现“类型视图中的setOnClickListner
方法不适用于参数”。 I also get a error on the line: 我也收到错误消息:
public void onClick(View v)
saying "The method onClick(View) of type new OnClickListener(){} must override or implement a supertype method". 说“类型为new OnClickListener(){}的方法onClick(View)必须重写或实现超类型方法”。 Code:
码:
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();
}
I feel like what you are trying to do is simply dismiss an alert using a different button other than one on the alert dialog. 我觉得您要尝试执行的操作只是使用警报对话框上的一个按钮(而不是按钮)来关闭警报。 Your best option would be to use VVVVVVVVVVVVVVVVVv
最好的选择是使用VVVVVVVVVVVVVVVVVv
dialog.setPositiveButton (CharSequence btnText, new DialogInterface.OnClickListener listener{
@Override
onClick(DialogInterface dialogInter, int whichBtn){
dialog.dismiss();
}
});
Theres no need to put a button in the view if you use an alertDialog.builder. 如果使用alertDialog.builder,则无需在视图中放置按钮。
Check out the link here 在这里查看链接
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.