我正在尝试通过关注帖子添加Ok button
并尝试该代码但不知何故它显示我错误
Builder (android.content.Context) in builder cannot be applied to (anonymous android.view.View.onClickListener)
这是我的代码
submit.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (Arrays.asList(input).contains("")){
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setMessage("You still have unanswered questions. Please go back");
alert.setTitle("Notice");
alert.setPositiveButton("OK",
new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which){
}
});
}else {
Intent in = new Intent(getApplicationContext(),gcfResult.class);
startActivity(in);
}
}
});
错误发生在this
关键字下面
AlertDialog.Builder alert = new AlertDialog.Builder(this);
答案 0 :(得分:2)
你需要使用
AlertDialog.Builder alert = new AlertDialog.Builder(YourActivityname.this);
因为new View.OnClickListener() {
是一个匿名类,而this
此处指的是anonymous
类而不是Activity