android中识别模块的问题

发布于 2024-12-03 15:00:01 字数 1487 浏览 0 评论 0原文

我对我试图实现的这个 android 代码感到非常困惑。我在 return new AlertDialog.Builder(this) 时遇到语法错误,它告诉我 .setMultiChoiceItems 无法识别。

谁能帮我解决这个问题吗?

@Override
protected Dialog onCreateDialog(int id){

switch(id){
case 0:
    return new AlertDialog.Builder(this)
    .setIcon(R.drawable.icon)
    .setTitle("This is a dialog with some simple text...")
    .setPositiveButton("OK", new 
        DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog,int whichButton)
        {
            Toast.makeText(getBaseContext(),"OK clicked!", Toast.LENGTH_SHORT).show();
        }
        })
        .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int WhichButton){
            Toast.makeText(getBaseContext(),"Ok clicked!", Toast.LENGTH_SHORT).show();
        }
    })
    .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog,int whichButton){

            Toast.makeText(getBaseContext(),"Cancel clicked!", Toast.LENGTH_SHORT).show();
        }
    }).setMultiChoiceItems(items, itemsChecked, new DialogInterface.OnMultiChoiceClickListener() {

        public void onClick(DialogInterface dialog, int which, boolean isChecked){
            Toast.makeText(getBaseContext(), items[which] + (isChecked ? " checked!": " unchecked!"), Toast.LENGTH_SHORT).show();
        }
    }
    )
.create();
}
return null;
}

I am quite baffled with this android code I'm trying to implement. I'm getting a syntax error at return new AlertDialog.Builder(this), and it is telling me that .setMultiChoiceItems is not recognized.

Can anyone help me fix this?

@Override
protected Dialog onCreateDialog(int id){

switch(id){
case 0:
    return new AlertDialog.Builder(this)
    .setIcon(R.drawable.icon)
    .setTitle("This is a dialog with some simple text...")
    .setPositiveButton("OK", new 
        DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog,int whichButton)
        {
            Toast.makeText(getBaseContext(),"OK clicked!", Toast.LENGTH_SHORT).show();
        }
        })
        .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int WhichButton){
            Toast.makeText(getBaseContext(),"Ok clicked!", Toast.LENGTH_SHORT).show();
        }
    })
    .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog,int whichButton){

            Toast.makeText(getBaseContext(),"Cancel clicked!", Toast.LENGTH_SHORT).show();
        }
    }).setMultiChoiceItems(items, itemsChecked, new DialogInterface.OnMultiChoiceClickListener() {

        public void onClick(DialogInterface dialog, int which, boolean isChecked){
            Toast.makeText(getBaseContext(), items[which] + (isChecked ? " checked!": " unchecked!"), Toast.LENGTH_SHORT).show();
        }
    }
    )
.create();
}
return null;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文