1. Download our Official Android App: Forums for Android!

Apps ListActivity and specifying different row layouts

Discussion in 'Android Development' started by Leolicos, Jun 20, 2010.

  1. Leolicos

    Leolicos Member
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    54
    Joined:
    Jun 16, 2010

    Jun 16, 2010
    54
    0
    15
    Senior Software Engineer
    Chicago, IL
    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 Member
    Rank:
    None
    Points:
    16
    Posts:
    49
    Joined:
    Sep 30, 2009

    Sep 30, 2009
    49
    5
    16
    San Francisco, CA
    You'll want to be using a PreferencesActivity.
     
  3. Leolicos

    Leolicos Member
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    54
    Joined:
    Jun 16, 2010

    Jun 16, 2010
    54
    0
    15
    Senior Software Engineer
    Chicago, IL
    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 Member
    Rank:
    None
    Points:
    16
    Posts:
    49
    Joined:
    Sep 30, 2009

    Sep 30, 2009
    49
    5
    16
    San Francisco, CA
    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...