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 8045363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:31:28+00:00 2026-06-05T05:31:28+00:00

I defined my preferences in xml file like the following: <PreferenceScreen xmlns:android=http://schemas.android.com/apk/res/android> <PreferenceScreen android:title=@string/pref_screen

  • 0

I defined my preferences in xml file like the following:

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceScreen
    android:title="@string/pref_screen"
    android:key="pref_screen_key">

    <CheckBoxPreference
        android:defaultValue="true"
        android:key="prefs1_key"
        android:title="@string/prefs1_str"
        android:summary="@string/prefs1_summary" />
        ....

Inside PreferenceActivity I override onPreferenceClick() for “pref_screen_key”:

     ...
     findPreference("pref_screen_key").setOnPreferenceClickListener(
     new OnPreferenceClickListener() {

     @Override
     public boolean onPreferenceClick(Preference preference) {
         if (flag) {
              // do some stuff
              return true; // According to Android doc it means, that click was handled
          } else
              return false;
     }

So I wish that Android will not open view with CheckBoxPreference if my flag is true, but just executes my stuff (I return true inside onPreferenceClick() to indicate that the click was handled and it is not needed to execute the default onPreferenceClick() behavior).
Unfortunately, Android always handles onPreferenceClick() with default behavior and makes my stuff at the same time.

Is it a bug in Android?
Is there a way to prevent Android from showing CheckBoxPreference after user clicks on PreferenceScreen?

  • 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-05T05:31:29+00:00Added an answer on June 5, 2026 at 5:31 am

    You’re probably running into problems with the fact that the flag must be declared final to be accessed inside the OnPreferenceClickListener. Try encapsulating it in a class and declaring the class final.

    To more directly answer your question, remember that when you return true from onPreferenceClick(), you’re telling the system “don’t worry, I handled it.” So, when you simply return true without actually doing anything, the system isn’t ignoring you, per se, you just told it to do nothing when the Preference is clicked.

    Your code looks similar to lines 108-115 of this example. Look through that and it may help.

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

Sidebar

Related Questions

In this example XML Layout of a PreferenceScreen : <PreferenceScreen xmlns:android=http://schemas.android.com/apk/res/android android:key=first_preferencescreen> <CheckBoxPreference android:key=wifi
I have xml file that defines some preference screens like the following example <PreferenceScreen
I've defined my preferences in an xml file, preferences.xml. I've also got a SettingsWindow
I have a PreferenceCategory , xml file and I have defined all preferences in
I have a working user-preferences screen which is defined in user_prefs.xml. The xml is
I am saving a number of preferences which are defined in an xml Preference
I have an Android Library Project that contains several styles/themes defined in its styles.xml
The beauty of PreferenceActivity is its tight integration with Android's res/xml . All you
I have a simple (not user-editable) numerical setting defined in a preferences XML as
Let's say I have a file-system that looks a little something like this: C:\stuff\build.xml

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.