A little change

Hi everybody,

I will change the way this blog works a bit. I want to blog more into the „software development“ / „Android“ direction than about my personal day to day drivers. Also I have the plan to rise the update frequency of this blog and the language changed to English so that users outside Germany can read what I write 🙂

So let’s start off with a little Android exercise. Recently I implemented a new language selector for Minimalistic Text. The old one just used the ListPreference in the Android Settings. My main goal has been to add little flags to each language to make this dialog a little more colored.

A short research on the internet showed me that there is no way to get images into a ListPreference. So I had to implement my own Preference that is capable of a list with images.
My first thought was to derive from ListPreference and add the image functionality. But due to the (lack of) design in the ListPreference there is no way to derive a subclass that implements another visual part. The main reason for this is the fact that the ListPreference stores the selected element index into an internal variable (private) that then gets read by the dialog closed event. So a subclass would have to set the index based on its own view to use the ListPreference functionality like propagating the settings change to all listeners.

So the last possibility has been to copy the ListPreference code to my own class and make images in the list possible.

The solution constists of 6 files:

  • ImageListPreference.java
  • ImagePreferenceArrayAdapter.java
  • imagelistpreferencelayout.xml
  • empty_content.xml
  • orange_content.xml
  • clickbackground.xml
The ImageListPreference is a copy of the ListPreference and adds an array of resource ids for the images. It sets its own ListAdapter to the Dialog (an instance of ImagePreferenceArrayAdapter). The Adapter then creates the views for the items based on the imagelistpreferencelayout and handles the click events (that set the currently selected index). The 3 drawable xml files are needed to give a visual feedback for tapping on an item (the background gets changed from empty to orange based on the selector in clickbackground.xml.)
You can download the sources for the ImageListPreference here: ImageListPreference.zip
That’s how the new language selector looks like:
Sample of the new Minimalistic Text language selector

Language Selector

If you have any questions or feedback for the ImageListPreference then write me an email.
Devmil

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.