Android – 更改首选项时确认对话框

任何人都可以建议我在更改CheckboxPreference或SwitchPrerence时执行AlertDialog以确认更改,
恩.如果我想取消选中Preference,AlertDialog应警告他们“你确定要取消选中吗?”加上对话框应该是可自定义的,因为我将使用自己的布局.我不想使用Dialog的Default Bluestrip Header.

SwitchPreference pref = (SwitchPreference) findPreference("prefkey_use_passcode");
    pref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference arg0, Object arg1) {
            DialogPreference dialog = new DialogPreference(getParent());

            return false;
        }
    });

解决方法:

这样的事情应该有效:

      AlertDialog.Builder builder = new AlertDialog.Builder (this);
      builder.setMessage (getString (R.string.are_you_sure));
      builder.setNegativeButton (getString(android.R.string.cancel),
                                 new DialogInterface.OnClickListener()
                                 {
                                   @Override
                                   public void onClick (DialogInterface dialog, int which)
                                   {
                                     finish();
                                   }
                                 });
      builder.setPositiveButton (getString(android.R.string.ok),
                                 new DialogInterface.OnClickListener()
                                 {
                                   @Override
                                   public void onClick (DialogInterface dialog, int which)
                                   {
                                     --- do the work to update the preference ---
                                     finish();
                                   }
                                 });
      builder.create().show();
      return;
上一篇:IEDA 自动生成类注释和方法注释


下一篇:IEDA的程序调试debug