ListActivity and specifying different row layouts


Last Updated:

  1. Leolicos

    Leolicos Well-Known Member This Topic's Starter

    Joined:
    Jun 16, 2010
    Messages:
    54
    Likes Received:
    0
    I'm trying to create a "settings" activity that consists of what is similar to the home page's settings page: there's big text, smaller text under it, then either a checkbox or a drop down that consists of radio buttons. I've looked at the ListActivity example but I'm not exactly sure what a Cursor is or does, nor what a URI is when creating a Cursor.

    I'm already up to the point where I have one layout that consists of a ListView, and 2 different layouts that specify 2 different rows the listview will have. Up to that point I'm not sure how to populate the listview and each row to be a particular layout and then the text inside it.
     

    Advertisement
  2. tdieckman

    tdieckman Well-Known Member

    Joined:
    Sep 30, 2009
    Messages:
    49
    Likes Received:
    5
    You'll want to be using a PreferencesActivity.
     
  3. Leolicos

    Leolicos Well-Known Member This Topic's Starter

    Joined:
    Jun 16, 2010
    Messages:
    54
    Likes Received:
    0
    I'm still confused... I looked at the PreferenceActivity page on android's doc and it showed methods such as adding resources via it's ID and it talks about a hierarchy.
     
  4. tdieckman

    tdieckman Well-Known Member

    Joined:
    Sep 30, 2009
    Messages:
    49
    Likes Received:
    5
    In Eclipse, choose File, New, Android XML File to bring up the XML file dialog. Choose Preference from the choices of what kind of XML file to build and fill in the name of the file.

    You can now create your PreferencesActivity preferences. It puts all your preference info in the XML file. Create your new Activity source file based off of PreferencesActivity and in the OnCreate, you just set it to use the xml file:

    addPreferencesFromResource(R.xml.user_preferences)

    ...where user_preferences is the name of your xml file that you created (i.e. user_preferences.xml in this example).

    Changes in the PreferencesActivity automatically write to the shared preferences, so you don't even have to worry about loading and saving values unless you're doing something more advanced.
     

Share This Page

Loading...