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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:04:46+00:00 2026-06-09T09:04:46+00:00

Ok so every post i find i cannot get this to work, i am

  • 0

Ok so every post i find i cannot get this to work, i am trying to inside my list preference

Settingsbasic.xml

<ListPreference
  android:title="themes"
  android:summary="Select the option of the list"
  android:key="listPref"
  android:entries="@array/Themes"
  android:entryValues="@array/list" 
  android:defaultValue="default" />

Now about as you can see above this is my listpreference inside my settingsbasic.xml file. Now what i need to know how to do is i have 2 java files, my main activity. and my preferences java file. I need to know how i can when the user clicks one of the the entries it does something, likes opens something or changes the ui, just something i think i can take it from there. I just need to know how and where the code would go. inside the main acitivty or preference activity.

here is my preference java file

  public class Prefs extends PreferenceActivity {

ListPreference listPref;

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.settingsbasic);


       }

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

 // Registers a callback to be invoked whenever a user changes a preference.
    getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);

} 

protected void onPause() {
    super.onPause();

 // Unregisters the listener set in onResume().
    // It's best practice to unregister listeners when your app isn't using them to cut down on
    // unnecessary system overhead. You do this in onPause().
    getPreferenceScreen()
            .getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);

  public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
        // Sets refreshDisplay to true so that when the user returns to the main
        // activity, the display refreshes to reflect the new settings.
        WebViewClientDemoActivity.????? = true;
    }

 }

Any example code would help, or adding on to my code above. I just need someone whom can shed some light on this code. i’ve tried so many different things and none of it works.

Ok so using the method of the sample app that was recommended below here is some more code i have .

 Main Activity   

  public class WebViewClientDemoActivity extends Activity {

    public static String sPref = null;

    public void onStart() {
        super.onStart();

     // Gets the user's network preference settings
        SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
     // Retrieves a string value for the preferences. The second parameter
        // is the default value to use if a preference value is not found.
        sPref = sharedPrefs.getString("listPref", "Default");

         }
  • 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-09T09:04:47+00:00Added an answer on June 9, 2026 at 9:04 am

    This is the way I used PreferenceActivity:

    public class EditPrefs extends PreferenceActivity {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            addPreferencesFromResource(R.xml.screen_prefs);
        }
    }
    

    Then in /res/xml folder I have the XML file:

    <PreferenceScreen
        xmlns:android="http://schemas.android.com/apk/res/android">
    
         <ListPreference
            android:key="txtColor"
            android:title="textView Color"
            android:summary="select color for textViews"
            android:entries="@array/txtColor"
            android:entryValues="@array/txtColorValues" />
    </PreferenceScreen>
    

    And in /res/values I have this XML file includes items and their values:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <string-array name="txtColor">
            <item>blue</item>
            <item>brown</item>
            <item>gray</item>
            <item>violet</item>
        </string-array>
        <string-array name="txtColorValues">
            <item>#ff000099</item>
            <item>#5F1E02</item>
            <item>#333333</item>
            <item>#421C52</item>
        </string-array>
    </resources>
    

    Then I easily call this class from another android class for instance when user clicks on a menu item:

    startActivity(new Intent(this, EditPrefs.class));
    

    You can call the preferences in onCreate and onResume like:

    @Override
    protected void onResume() {  
        super.onResume();
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        String txtColor = prefs.getString("txtColor", DEFAULT COLOR); // for instanse : #ff000099 
        textView.setBackgroundColor(Color.parseColor(txtColor));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've gone through every post I could find on this site and the Java
I've read every post I can find about this but nothing is working. I'm
I've read every post about this issue, but nothing solved the problem. I'll be
I applied .drop_cap class to the first letter of every post, such as this:
I have this PHP code in a loop for every post on the admin
I have made this mistake several times, and found myself referencing This Post every
Every time I try to run my script I get this error, saying that
I have tried finding an answer to this problem and in every post I
How can I get this query to work where it goes through the checks
I've browsed every post about TFS and Hudson I could find but nothing useful

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.