I am trying to create a preference screen for an Android project I’m developing.
I have created a XML config file, which I’ve been using for debug, but now I want to create a more user friendly way to set the preferences for the application, and decided to go for the Preference Screen.
As part of this project, I have a RSS Feed reader, for which I want to be able to set more than one URL feed, but I can’t figure out how. What I really need is something that will let me add a new URL (or remove one) to a list of configured URLs in Preferences.
As an example, here’s the rss part of the xml I’ve been using for debug matters (fetching data):
<source type="rss">
<active>true</active>
<target_url>http://feeds.tsf.pt/TSF-Ultimas</target_url>
<target_url>http://www.arcamax.com/thefunnies/garfield/rss</target_url>
</source>
I nailed it. I created a new preference called AddButtonPreference, extending Preference, that basically creates a button and points its OnClickListener to the Activity that creates this preference.
To create the list, I iterate over my target list to add EditTextPreferences to the PreferenceScreen, and after iterating them, I add the buttonPreference. Then I just implemented the onClick, to add a new EditTextPreference to that screen when clicked, and move the button to the end.