Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7545809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:01:40+00:00 2026-05-30T09:01:40+00:00

I am doing a preferenceScreen with this xml code: <PreferenceScreen xmlns:android=http://schemas.android.com/apk/res/android android:orderingFromXml=true> <PreferenceCategory android:key=pref1

  • 0

I am doing a preferenceScreen with this xml code:

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" android:orderingFromXml="true">
<PreferenceCategory 
       android:key="pref1" 
       android:title="Search All">
    <CheckBoxPreference 
          android:key="check_all" 
          android:title="Check"/>
</PreferenceCategory>
<PreferenceCategory 
       android:title="Specific Search" 
       android:key="pref2">
    <ListPreference 
          android:title="Food" 
          android:key="opcion1"
          android:dialogTitle="Escoge Categoria"
          android:entryValues="@array/codigoCateg" 
          android:entries="@array/categorias" 
          android:negativeButtonText="Cancel"/>
    <ListPreference android:title="Dificultad"/>
    <ListPreference android:title="Otras"/>
</PreferenceCategory>

Java code:

public class OpcionesBusqueda extends PreferenceActivity {

boolean CheckBoxPreference;
private PreferenceCategory Pref2;


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.video_search);

    Pref2=(PreferenceCategory)findPreference("pref2");

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

    CheckBoxPreference = prefs.getBoolean("check_all", true);

    if(CheckBoxPreference==true){
        Pref2.setEnabled(false);
    }
    else{
        Pref2.setEnabled(true);
    }
}

}

What I would like to do is if the checkbox is checked then the pref2 (preferencecategory2) should be disabled and if it is unchecked, it should be enabled. There is something that I’m doing wrong, or maybe more than one.

Thanks.


I followed Alex’s answer and with some changes I arrived to the desire code, here is the code corrected:

public class OpcionesBusqueda extends PreferenceActivity {

private CheckBoxPreference Check;
private PreferenceCategory Pref2;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.video_search);

    Check=(CheckBoxPreference)findPreference("check_all");
    Pref2=(PreferenceCategory)findPreference("pref2");

    Check.setOnPreferenceChangeListener(new CheckBoxPreference.OnPreferenceChangeListener() {
        public boolean onPreferenceChange(final Preference preference, final Object newValue) {
                Pref2.setEnabled((Boolean)newValue == false);
                return true;
        }
    });        

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T09:01:42+00:00Added an answer on May 30, 2026 at 9:01 am

    You may want to set OnPreferenceChangeListener for the check_all preference and change pref2 inside onPreferenceChaged of that OnPreferenceChangeListener

    CheckBoxPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
         boolean onPreferenceChange(Preference preference, Object newValue) {
              Pref2.setEnabled((Boolean)newValue == false); 
         }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider this preferences.xml file: <?xml version=1.0 encoding=utf-8?> <PreferenceScreen xmlns:android=http://schemas.android.com/apk/res/android android:title=@string/preference_main> <PreferenceScreen android:title=@string/preference_sight android:key=category_sight> <ListPreference
Doing this: @resp = Net::HTTP.get_response(api.something.com, /feed/v1/offers.json?#{@params_api_string}) I get this response in @resp: #<Net::HTTPOK:0x7f451e9d3ef0> How
Doing a code review I've stumbled over GWM in Java-Spring-GWT web-application. As this product
Doing this: s = hello s[0] outputs the character code value 104 . What
Doing Android development on a Mac and this very new phone I have doesn't
Doing an ajax get request works as expected using the following code: $.ajax({ type:
When doing TDD , how to tell that's enough tests for this class /
I've done this before...not sure what i'm doing wrong now I know it's the
Doing something like this: from zipfile import ZipFile #open zip file zipfile = ZipFile('Photo.zip')
doing this in AppDelegate: viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil]; Is there any problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.