【问题标题】:change CheckBoxPreferesses if normal checkbox is chackedchange CheckBox Preferences of normal checkbox被选中
【发布时间】:2015-03-25 11:19:43
【问题描述】:

我正在开发一个 android 应用程序,我在我的注册布局中有一个复选框,可以从我的设置中编辑一个值(设置是 sharedpreferences) 因此,当用户注册可以选中该复选框并且如果选中了此复选框以便我的设置中的一个(CheckBoxPreferences),我的问题是如何根据注册活动中的复选框是否被选中来更改 CheckBoxPreferences 值?

谢谢

【问题讨论】:

  • 您可以根据值检查或取消选中 CheckBoxPreferences 将值存储在共享首选项等位置

标签: android checkbox sharedpreferences checkboxpreference


【解决方案1】:

CheckBox 值存储在 SharedPreferncesand based on value ofSharedPreferences, setCheckBoxPreference` 以选中/取消选中

boolean isCheckBoxChecked = <GetCheckBoxState>;
SharedPreferences prefs = getSharedPreferences("PrefsName", <Mode>);
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("<Key>", isCheckBoxChecked).commit();

//Retrieve SharedPreferences value and set it to CheckBoxPreference
boolean value = prefs.getBoolean("<Key>", <DefaultValue>);
CheckBoxPreference cbPref = (CheckBoxPreference) findPreference("<YourPreference>");
cbPref.setChecked(value);

【讨论】:

    【解决方案2】:
    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    
            <item android:drawable="@drawable/layer176"
                android:state_checked="false"/>
            <item android:drawable="@drawable/checked250"
                android:state_checked="true"/>
            <item android:drawable="@drawable/layer176"/>
    
    </selector>
    
    
    ========================================================
    
    <CheckBox
            android:id="@+id/slider_listview_row_checkbox"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:button="@drawable/checkbox_selector"
            android:background="@null"
            />
    
    
    You can use above xml code ..
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-08
      • 1970-01-01
      • 2018-02-03
      • 1970-01-01
      • 2012-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多