0

I have 2 preference pages. Depending on a checkbox displayed on the preference page "one" I want to display a CheckBoxPreference or not display it on the page "two". I know that I should add on the activity of the page "two" a way to handle if the checkbox in the page "one" is checked or not. But i don't know how to refer on that checkbox.

Cœur
  • 37,241
  • 25
  • 195
  • 267

2 Answers2

0

Save the checkbox's state by getting a reference to it programmatically, save it's state as a preference, pass it in an intent (via intent.putExtras();) or save it in SharedPreferences, then on the second activity check if the CheckBoxPreference.isChecked() then conditionally load preferences. Check here for more information.

George Daramouskas
  • 3,720
  • 3
  • 22
  • 51
  • Can you provide an example on how to do this? My problem is that i don't know how to refer in a CheckBoxPreference from the xml. –  Mar 02 '15 at 11:54
  • You refer to a CheckBoxPreference the same way you refer to any other object that is defined in XML eg: CheckBoxPreference checkBox = (CheckBoxPreference) findViewById(R.id.yourCheckBox). – George Daramouskas Mar 02 '15 at 12:06
0

You could use a class named StaticValues and add a variable that it is boolean.

public static boolean isCheckBoxChecked;

When the checkbox is checked set this variable true:

StaticValues.isCheckBoxChecked = true;

When you are displaying preference page 2 you can check this variable and deside if you diplay the next checkbox or not.

Painful
  • 137
  • 1
  • 11