Monday, November 11, 2013

Help, my spinner is too wide!


When dealing with the Spinner widget, especially when using NAVIGATION_MODE_LIST in your Actionbar, you might have stumbled over its weird sizing behavior. Namely, it's much wider than it needs to be. Here's an example of what a spinner in the Actionbar might look like:

The spinner is apparently much wider than it needs to be.
In this post I will explain what the reason for this behavior is, highlight the responsible bit of code from the Android framework and present a method for fixing it.

Saturday, November 2, 2013

Multiple dependencies in Android preferences

While adding a new feature to my Android app Changelog Droid I discovered the need for a checkbox preference that is dependent on two separate preferences, i.e. the preference is only enabled if two other preferences are cheked. If either one is unchecked, it should be disabled. The (simplified) hierarchy looks as follows:

  • Enable notifications
    • Enable notifications for updated apps
      • Enable detailed notifications for updated apps

Logically, the preference "Enable detailed notifications" should only be enabled, if "Enable notifications for updated apps" is checked and both should only be enabled, if "Enable notifications" is checked. I googled a bit to find out there is no built-in way to achieve this, as preferences can only have one value for the "dependency" attribute, so I created my own implementation.