Victor
Victor

Reputation: 666

Android PreferenceScreen Preferences

I am new to Android development. I have developed a preferences activity in my Android Application. I wanted one Preference to open up a regular Activity. I created a preference object in my XML file and captured the onclick event in order to open the activity. Code below:

 <PreferenceCategory android:title="School">
  <Preference
    android:key="txtSchoolListPreference"
    android:title="Select School"
    android:clickable="true" />
</PreferenceCategory>

    // Get selected school text box
    Preference SelectedSchool =(Preference)findPreference("txtSchoolListPreference");

    SelectedSchool.setOnPreferenceClickListener(new OnPreferenceClickListener() {
         public boolean onPreferenceClick(Preference preference) {
             // Show the login intent
             Intent i = new Intent(Settings.this,SchoolList.class);
             i.putExtra(One.APP_ACTIVITY_NAME,One.APP_ACTIVITY_SETTINGS);
             startActivityForResult(i, One.APP_ACTIVITY_SCHOOLLIST);
             return true;
         }
    });

Everything works great but I would like to add the circle arrow-down icon to the preference but I don't know how.

Does anyone have any idea how I can add the circle arrow-down preference to the preference I have added to the page?

Upvotes: 2

Views: 1139

Answers (1)

Dan S
Dan S

Reputation: 9189

Getting the PreferenceActivity to show like the system's current theme is a bit more involved. Than just showing the Android vanilla arrow. You'll have to create a subclass of DialogPreference (code on github). Use the code from EditTextPreference (code on github) as a template on how to create your subclass. As it appears you'll be starting another Activity this will be easier than creating one that displays another dialog (was not that easy in my experience).

To include your preference in the Preference Resource xml file use the fully qualified name with a leading capital letter. For example class Foo in package com.stackoverflow would appear as <Com.stackoverflow.Foo>. This is similar to how custom view widgets are used in xml layouts.

The reason you have to do it this way is the arrow is an internal resource so we have to go to some extremes to use the internal resource.

Upvotes: 1

Related Questions