java - AlertDialog.Builder 类型中的 setPositiveButton(int, DialogInterface.OnClickListener) 不适用于参数

标签 java android

ERROR: /home/gabr0/Escritorio/Andorid/packages/apps/OwlsNest/src/com/aosip/owlsnest/advanced/ScreenStateToggles.java:187.26: The method setPositiveButton(int, DialogInterface.OnClickListener) in the type AlertDialog.Builder is not applicable for the arguments (int, new OnclickListener(){}) ERROR: /home/gabr0/Escritorio/Andorid/packages/apps/OwlsNest/src/com/aosip/owlsnest/advanced/ScreenStateToggles.java:187.83: DialogInterface cannot be resolved to a type ERROR: /home/gabr0/Escritorio/Andorid/packages/apps/OwlsNest/src/com/aosip/owlsnest/advanced/ScreenStateToggles.java:188.41: DialogInterface cannot be resolved to a type ERROR: /home/gabr0/Escritorio/Andorid/packages/apps/OwlsNest/src/com/aosip/owlsnest/advanced/ScreenStateToggles.java:195.88: DialogInterface cannot be resolved to a type ERROR: /home/gabr0/Escritorio/Andorid/packages/apps/OwlsNest/src/com/aosip/owlsnest/advanced/ScreenStateToggles.java:196.49: DialogInterface cannot be resolved to a type

代码

 if (value == true){
                AlertDialog.Builder builder = new AlertDialog.Builder(mContext,android.R.style.Theme_Material_Dialog_Alert);
                builder.setTitle(R.string.screen_state_twogtitle)
                        .setMessage(R.string.screen_state_twogmessage)
                        .setPositiveButton(R.string.screen_state_twogconnect, new DialogInterface.OnclickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        Settings.System.putInt(resolver, Settings.System.SCREEN_STATE_TWOG, value ? 1 : 0);


                    Intent intent = new Intent("android.intent.action.SCREEN_STATE_SERVICE_UPDATE");
                    mContext.sendBroadcast(intent);
                }})
                        .setNegativeButton(R.string.screen_state_twogdontconnect,  new DialogInterface.OnclickListener(){
                            public void onClick(DialogInterface dialog, int which){
                            value = !value;
                            }
                        })
                        .show();}return true;}

最佳答案

setPositiveButton()setNegativeButton() 调用中,您尝试使用 DialogInterface.OnclickListener。此类的正确名称是 DialogInterface.OnClickListener,其中“Click”大写。

关于java - AlertDialog.Builder 类型中的 setPositiveButton(int, DialogInterface.OnClickListener) 不适用于参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49056801/

相关文章:

android - 完成Retrofit调用后如何调用方法?

java - 推荐一个 Java/Android 游戏库——卡、板等?

java - AlarmManager BroadcastReceiver,onReceive 从未被调用

java - 如何用java制作沙盒游戏

android - 设置另一个 Activity 的 TextView 但未初始化

java - Android线性布局背景透明度

android - Fragment 的菜单项被多次添加

java - 对于 java 上的幻想草稿程序,我如何将数据从文本文件加载到单独的 ArrayList 列表中?

java - 关于 Akka 和类型安全的一般问题

java - 如何迭代 Future<List> 对象?