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

  • SEARCH
  • Home
  • 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 8322313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:20:49+00:00 2026-06-08T23:20:49+00:00

I have a PreferenceActivity where I represent a setting UI, when I press the

  • 0

I have a PreferenceActivity where I represent a setting UI, when I press the first checkbox then the second checkbox becomes visible. On the other hand, when the first checkbox is unchecked the second checkbox is hidden(and gets a default value to false).

The problem is that I need my UI screen to be refreshed the moment I check(or uncheck) the first checkbox because right now with that code I need to go to another Activity (e.g when I press the back button) and then get back to the PreferenceActivity again in order to see the changes on my UI.

Code for PreferenceActivity:

public class SetPreference extends PreferenceActivity implements
        OnSharedPreferenceChangeListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.checkboxpref);
    }

    @Override
    protected void onStart() {
        super.onStart();

        Preference checkbox = findPreference("checkBox_Schedule");

        SharedPreferences prefs = PreferenceManager
                .getDefaultSharedPreferences(this);

        if (prefs.getBoolean("checkBox", true)) {

        } else {

            ((PreferenceGroup) findPreference("category_second"))
                    .removePreference(checkbox);

            SharedPreferences.Editor geted = prefs.edit();
            geted.putBoolean("checkBox_Schedule", false);
            geted.commit();
        }
    }

    @Override
    protected void onResume() {
        super.onResume();

    }

    @Override
    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
            String key) {
        // TODO Auto-generated method stub

    }

}

Code for XML:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >

    <PreferenceCategory
        android:summary="Username and password information"
        android:title="Login information" >
        <EditTextPreference
            android:key="username"
            android:summary="Please enter your login username"
            android:title="Username" />
        <EditTextPreference
            android:inputType="textPassword"
            android:key="password"
            android:summary="Enter your password"
            android:title="Password" />
    </PreferenceCategory>
    <PreferenceCategory
        android:summary="Username and password information"
        android:title="Settings"
        android:key="category_first" >
        <CheckBoxPreference
            android:key="checkBox"
            android:summary="On/Off"
            android:title="Keep me logged in" />

        <ListPreference
            android:entries="@array/listOptions"
            android:entryValues="@array/listValues"
            android:key="listpref"
            android:summary="List preference example"
            android:title="List preference" />
    </PreferenceCategory>
    <PreferenceCategory
        android:summary="schedule"
        android:key="category_second"
        android:title="Schedule" >
        <CheckBoxPreference
            android:key="checkBox_Schedule"
            android:summary="On/Off"
            android:title="Keep me logged in" />
    </PreferenceCategory>

</PreferenceScreen>

Thank you for your time.

  • 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-06-08T23:20:51+00:00Added an answer on June 8, 2026 at 11:20 pm

    Ok then just restart the activity when the checkbox is selected/deselected:

    startActivity(new Intent(PreferencesActivity.this, PreferencesActivity.class));
    finish();
    

    Consider using onPreferenceSelectedListener for the first checkbox to detect the act of checking/unchecking the preference.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PreferenceActivity that contains a RingtonePrefernce built in xml along with other
I have a PreferenceActivity class that handles the getting and setting of preferences within
I have SettingsActivity that extends PreferenceActivity and in setting I can specify how many
I have a settings class that extends PreferenceActivity. I have a checkbox preference in
I have a couple of ListPreferences that my PreferenceActivity displays. From the class that
I have need for AutoCompliteTextView in PreferenceActivity so I extended DialogPreference. My auto-complite is
In my extended PreferenceActivity class I call addPreferencesFromResource(R.xml.livewallpaper_settings) so I have a xml file
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
I have an PreferenceActivity where I would like to add Preferences dynamically. On a
I have used PreferenceActivity to have preference in my android application. I want one

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.