Blogs

Android: Generic methods to write/save Android preferences data

I was working with Android Preferences recently, and after writing a few “save my preference” methods, I decided to take a few minutes to organize my code and put all of those Preference methods in a PreferenceUtils class. I made the methods static, and following functional programming principles, I made their output depend only on their input, so they require you to pass in a Context reference, along with your preference key and value.

Android ActionBar example: How to create an options menu item

As Android programming goes, creating an options menu item/button in the Android ActionBar is fairly straightforward. In this brief tutorial I’ll demonstrate all of the steps needed to add a new menu item to the action bar.

1) Define the view/layout

The first step is to declare what the menu “view” is going to look like. This is very similar to defining other Android views, you do it with an XML layout file.

Syndicate content