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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:56:43+00:00 2026-05-25T05:56:43+00:00

I have set the Preferences in xml and I have the folowing Activity: public

  • 0

I have set the Preferences in xml and I have the folowing Activity:

public class Preferencias extends PreferenceActivity {

//SharedPreferences prefs;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


    addPreferencesFromResource(R.xml.preferences);

    setContentView(R.layout.preferences);

    Button bt=(Button)findViewById(R.id.selectPic);
    TextView tv=(TextView) findViewById(R.id.textView1);
    String def=getResources().getString(R.string.noDefinido);
    tv.setText(PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("logo", def));


    bt.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
             Intent intent = new Intent(Intent.ACTION_VIEW);

                intent.setClassName(getApplicationContext(),
                        SDCardImagesActivity.class.getName());
                startActivity(intent);
        }
    });

    //habra que sacarlo de la red
    String [] ofis ={"Venus", "Europa"};
    ListPreference lp=new ListPreference(this);
    lp.setValue("oficina");
    lp.setEntries(ofis);
    lp.setEntryValues(ofis);
    lp.setTitle(R.string.oficina);
    lp.setDefaultValue(ofis[1]);


    getPreferenceScreen().addPreference(lp);


}
}

It works fine with the xml preferences but I also need to add a preference in code the reason of it is that the options of this ListPreference will come from the database (here I have the String array for now). The problem is the data changed for this preference is not persisted. When I make the changes I press back button I come back the value goes back to default value. How could I make sure this preference is saved too?

Thanks a lot

  • 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-25T05:56:44+00:00Added an answer on May 25, 2026 at 5:56 am

    solved I included the preference without setting up its data then in code:

    String [] ofis ={"Venus", "Europa"}; 
    ListPreference lp=(ListPreference) getPreferenceManager().findPreference("oficina");  
    lp.setEntries(ofis); 
    lp.setEntryValues(ofis); 
    lp.setDefaultValue(ofis[1]); 
    

    works fine now

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

Sidebar

Related Questions

import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; import android.preference.PreferenceActivity; public class Preferences extends
I have 1 PreferenceActivity in preferences.xml is <CheckBoxPreference android:id=@+id/pushCB android:checked=true android:defaultValue=true android:key=PushService android:summary=Set to
I have a settings class that extends PreferenceActivity. I have a checkbox preference in
I have a class called FileGeneration that extends Activity In FileGeneration I have a
I'm using PreferenceActivity to set some preferences about another BroadcastReciever that i have. While
I have a PreferenceActivity that loads its preferences from an XML file which looks
I have a preferences.xml file that I use to set up preferences that will
I have two switches set up in a preferences.xml file. <SwitchPreference android:summaryOff=Metric Units android:summaryOn
I have set the two buttons in preference.xml file. I want to go to
I have set up an app that is registered for remote notifications. - (void)application:(UIApplication*)application

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.