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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:54:26+00:00 2026-05-29T21:54:26+00:00

I’m trying to work this function but I can’t. My application hasn’t got a

  • 0

I’m trying to work this function but I can’t. My application hasn’t got a SQL database, it has only .xml files. I would like to change file to view by the preferences settings, for example I would be able to view or the file data.xml or the file data2.xml checking or unchecking a checkbox.

Activity PreferencesFromXml:

public class PreferencesFromXml extends PreferenceActivity{

    public static final String COLORE_DEFAULT = "#000000";

    public static final String COLORE_PREF = "colore";

    public static final String TITOLO_PREF = "titolo";

    public static final String USA_TITOLO_CUSTOM_PREF = "usa_titolo_custom";

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

            addPreferencesFromResource(R.xml.preferences);

            SharedPreferences prefs =     PreferenceManager.getDefaultSharedPreferences(this);

            Preference titoloPrefs = findPreference(TITOLO_PREF);
            titoloPrefs.setSummary(prefs.getString(TITOLO_PREF, getString(R.string.titolo_custom)));
            titoloPrefs.setOnPreferenceChangeListener(new OnPreferenceChangeListener()
            {
                    public boolean onPreferenceChange(Preference prefs, Object value)
                    {
                            prefs.setSummary((CharSequence) value);
                            return true;
                    }
            });
    }
}

Main Activity:

public class Main extends ExpandableListActivity{
    ExpandableListAdapter mAdapter;
    private ArrayList<Group> groups;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.list_main);

            groups = readGroupsFromXml();

            mAdapter = new MyExpandableListAdapter(getLayoutInflater(), groups);
            setListAdapter(mAdapter);
            registerForContextMenu(getExpandableListView());
    }

    public ArrayList<Group> readGroupsFromXml()
    {
            try
            {
                    final XmlHandler handler = new XmlHandler();
                    final SAXParser sp = SAXParserFactory.newInstance().newSAXParser();
                    sp.parse(getApplicationContext().getResources().openRawResource(R.raw.data), handler);
                    return handler.getGroups();
            }
            catch (Exception e)
            {
                    Log.e("Error", "xml", e);
            }
            return null;
    }

Then I don’t know what to do to choose the file to use when the checkbox is selected or not. I stopped here (although I don’t know if it’s correct):

@Override
protected void onResume(){
    super.onResume();
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    Editor editor = prefs.edit();

    String usa_titolo_custom;
            if (prefs.getBoolean(PreferencesFromXml.USA_TITOLO_CUSTOM_PREF, false))
            {

As you can see from the code .xml files are located in res/raw. Thank you for your help.

  • 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-29T21:54:28+00:00Added an answer on May 29, 2026 at 9:54 pm

    just set up a boolean shared prefs and use it. Put these as global variables …

    SharedPreferences data;
    public static String filename = "filename";
    boolean b;
    

    Then in onCreate() put

    data = getSharedPreferences(filename, 0);
    

    set the boolean with

    SharedPreferences.Editor editor = data.edit();
    editor.putBoolean("data", b);
    editor.commit();
    

    get the boolean like this, where default is true or false, depending on what you want it to be if it’s not set.

     b = data.getBoolean("data", default);
    

    then use something like

    public ArrayList<Group> readGroupsFromXml() {
    
    b = data.getBoolean("data", false);
    if (b == true){ 
        try {
            final XmlHandler handler = new XmlHandler();
            final SAXParser sp = SAXParserFactory.newInstance().newSAXParser();
            sp.parse(getApplicationContext().getResources().openRawResource(R.raw.data), handler);
            return handler.getGroups();
        } catch (Exception e) {
            Log.e("Error", "xml", e);
        } 
    } else {
        try {
            final XmlHandler handler = new XmlHandler();
            final SAXParser sp = SAXParserFactory.newInstance().newSAXParser();
            sp.parse(getApplicationContext().getResources().openRawResource(R.raw.data2), handler);
            return handler.getGroups();
        } catch (Exception e) {
            Log.e("Error", "xml", e);
            }
        }
    return null;
    
    }
    

    If b is true it uses data.xml, if it’s false it uses data2.xml.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Basically, what I'm trying to create is a page of div tags, each has
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
Does anyone know how can I replace this 2 symbol below from the string
I want to construct a data frame in an Rcpp function, but when I
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.