android preferences - CheckBoxPreference group that act like Radio -
I had to launch more than one checkbox on the same screen which would act like a radio list, I saw some implementation of it, But finally I wrote some of my own. Maybe it will help someone.
1) Create a group class, such as:
public class Checkbox field group {Private list & lt; Checkbox presentation & gt; MGroup; Public Checkbox PrefricaSGroup (Primary Manager Manager, String [] key) {mGroup = New Arrestist & lt; Checkbox projection & gt; (Keys.length); For (int i = 0; i & lt; keys; lamps; i ++) {last checkbox presentation cbx = (checkbox presentation) manager.findPreference (key [i]); Cbx.setOnPreferenceClickListener (New OnPreferenceClickListener () {public boolean onPreferenceClick (Priority Priority) {onCheckBoxClick (cbx); Back to True;}}); MGroup.add (cbx); }} Private zero on checkbox, checkbox (new checked) {checkbox checked checked = zero; (Checkbox presentation item: mgut) {if (item! = New check & item checked ()) {old che = item; break; }} If old check! =) Old Chekhed. Set check (wrong); }} 2) Provide with an array of strings (string [] key) so that he can search for preferences.
3) Use it like this: Increases the public frozen square settings preferences interface {Private Static Checkbox Proprietary Group Mellert Group; Override public null on @reate (bundle saved instainstate) {super.naught (savedinstenstate); AddPreferencesFromResource (R.xml.preferences_screen_notifications); PreferenceManager.setDefaultValues (getActivity (). GetApplicationContext (), R.xml.preferences, false); PreferenceManager pm = getPreferenceManager (); MAlertGroup = New checkbox presentation group (pm, getResources (). GetStringArray (R.RA.PREF_Watchbox)); }} Where pref_checkboxes is my string array checkbox key: & lt; String-array name = "pref_checkboxes" & gt; & Lt; Items & gt; Pref_cbx1 & lt; / Item & gt; & Lt; Items & gt; Pref_cbx2 & lt; / Item & gt; & Lt; Items & gt; Pref_cbx3 & lt; / Item & gt; & Lt; Items & gt; Pref_cbx4 & lt; / Item & gt; & Lt; / String array & gt;
Comments
Post a Comment