所以我在这里搜索了几个关于 AlertDialog 的问题,但我不完全确定我在做什么,所以我很难将这些问题与我自己的示例相关联。 (我对整个 Android 编程还是陌生的,所以请多多包涵。)
我已经在公共(public)类下定义了这个 _ Activity implements OnCLickListener ...
public AlertDialog myAlertDialog;
然后我在 onClick 下有这个
public void onClick(View src) {
switch(src.getId()){
case R.id.buttonOk:
if (score==0){
AlertDialog.Builder myAlertDialog = new AlertDialog.Builder(this);
myAlertDialog.setTitle("Title");
myAlertDialog.setMessage("Message");
myAlertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
return;
} });
myAlertDialog.show();
}
这一行及其下一行有错误:
myAlertDialog.setButton("OK", new DialogInterface.OnClickListener() {
错误:
第一个:这条线上有多个标记 - DialogInterface 无法解析为类型 - 方法 setButton(String, new OnClickListener(){}) 未定义类型
第二:DialogInterface 无法解析为类型
谁能告诉我我做错了什么?
谢谢!
最佳答案
我很确定您只是没有导入 DialogInterface。尝试将此语句添加到代码的开头。
import android.content.DialogInterface;
关于android - AlertDialog - 试图让警报工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6259358/