【发布时间】:2013-01-24 06:20:05
【问题描述】:
我正在尝试创建自定义对话框。当我调用 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();
}
【问题讨论】:
-
您是先解散然后再显示吗?这就是它出现在这里的样子。也许只是复制并粘贴确切的代码,而不是在中间解释它,因为它有点模棱两可。
-
以后请准确复制粘贴您的代码,不要尝试在中间添加解释。如果您想引用特定行,请在该行上或上方添加评论并提及。您发布代码的方式几乎不可能告诉它发生了什么,并且它包含一些看似错误的括号和括号。我试图尽可能地修复格式,但我不愿意猜测解决方案,因为我无法确定我是否理解您所面临的问题。在“不适用于参数”之后有没有说什么?
-
您是否遇到编译器错误?可能是你没有导入正确的包!
标签: android