Tuesday, December 30, 2014

Friday, June 20, 2014

Maintaining selection in ListView for multi-pane layouts

In this post, I will walk through setting up a list item that will remain In this post, I will walk through setting up a list item that will remain in a selected state after the user presses on an item. This is useful when you have a multi-pane layout and you want to show details for an item in a fragment next to the list view and keep the list item highlighted so your user doesn't loose context.

Below I'll lay out the steps to accomplish this goal with code snippets.

First, you'll need to set up your ListView's choiceMode by setting it to singleChoice.

    <ListView android:id="@+id/list_view"

At this point, your list item will have an activated state when the user presses it. But, we haven't set up what it should look like when in this state. For this example, it will change background color to set it apart from the rest of the list items.

To do that, we'll create a selector drawable and define another drawable for it's state_activated attribute. (Here we are just using a color resource, but it could be any type of drawable.)

<selector xmlns:android="">
    <item android:state_activated="true"
Now that we've defined a selector to handle the activiated state, we just need to set the selector as the background for the root layout that defines this list item.

<LinearLayout xmlns:android="">
And that's it! Now you have a ListView where the selected item will maintain it's selected state for use in multi-pane layouts.

Monday, July 1, 2013

Install Rails on Mac

Get Rails installed on your Mac from scratch

These steps are the simplest way that I've found to get up and running quickly with a Rails development environment.  If you plan on deploying to Heroku, you'll want to go ahead and install the PostgreSQL database instead of using the default Sqlite database.
  1. Xcode
  2. Command Lines Tools (GCC)
    • Open Xcode -> Preferences -> Downloads
    • Download the Command Line Tools
  3. RVM (latest stable)
    • $ \curl -L | bash -s stable
  4. Ruby (latest stable)
    • $ rvm install ruby
  5. Rails (latest stable)
    • $ gem install rails

Optional but recommended

  1. Homebrew
    • $ ruby -e "$(curl -fsSL"
  2. PostgreSQL
    • $ brew install postgres

Thursday, August 18, 2011

Android "has invalid digest" Error

I came across this error and lost two days trying to get it figured out so I thought I'd share the resolution.

I recently built a new build server and as usual, just installed the latest version of the Java JDK (which is now 7). The build seemed to work OK and there are no errors reported, however when attempting to install the APK, it fails and the logcat reports an error containing "has invalid digest".

I'm not exactly sure of the cause but is related to the way the APK is signed when running the JDK7.

Once I uninstalled JDK7 and installed JDK6, all was well.

Sunday, May 8, 2011

Building Android LVL Project - Error: Cannot compute package for file

Since my search for this error yielded zero results I'm creating this post to hopefully help some of you going forward.

If you get this error while you are trying to build an Android project with the Licensing library (LVL), all you need to do is exclude the 'aidl' folder from being built.

Friday, September 10, 2010

MonoDroid "aresgen.exe" Error

I just installed the MonoDroid build 1.0.7931 Visual Studio plugin today and went to build my first Hello World app when I encountered the following error:

"aresgen.exe" exited with code -1

At first I wasn't sure what was wrong but after some toiling, realized that I had installed my android sdk in a non-standard location. So, if you encounter this same issue just move your sdk to "C:\android-sdk-windows" and all will be well.

Happy MonodDroid-ing

Tuesday, June 8, 2010

Customizing Android ListView Colors

Since I struggled through getting a ListView to have custom colors, I am going to share exactly what is needed so others can avoid the struggle.

Below are the details for the resources required to accomplish this.  These resources will give your list items a white background with a highlighted color of blue and a clicked of green.

I've highlighted the key attributes in bold.  These are the attributes that differ from your default list.

File: res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
File: res/layout/item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android=""

File: res/drawable/item_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="">
     android:drawable="@color/green" />
     android:drawable="@color/blue" />
     android:drawable="@color/white" />

File: res/values/colors.xml
<?xml version="1.0" encoding="utf-8"?>
 <color name="red">#ff00</color>
 <color name="green">#f0f0</color>
 <color name="blue">#f00f</color>
 <color name="white">#ffff</color>
 <color name="black">#f000</color>

Related Links:
Resource Types
Color State List

Tuesday, March 16, 2010

Setting up the ADT in Windows 7

When I set up the Android Development Toolkit in Eclipse running on Windows 7, I ran into an issue installing the platform packages. Luckily I knew why it didn't work but anyone new to the stricter Windows 7 security settings may be at a loss.

So, if you run into issues installing the platform packages it is because you are probably installing them to a folder with higher security settings and therefore need to run Eclipse as an administrator for this to work.

One way to do this permanently is to go to the properties of the eclipse shortcut you are running and in the compatibility tab check the box to always run as administrator. Unfortunately you will always be prompted by windows when starting up. (I believe there is a way to turn this off as well)

NOTE: If your Workspace folder is located in your user folder, you will have to set everything back up under the administrator user.

Thursday, February 18, 2010

Creating AVD's

As promised I am updating you on things I learned during my initial setup of the Android environment.

So the first time around I was following the Google documentation and created an AVD using the terminal and while I appreciate the power of command lines, I am a sucker for GUI's.  Thankfully I have discovered that you can create and manage AVD's inside of Eclipse by going to: Window -> Android SDK and AVD Manager.

Once you are in the Android SDK and AVD Manager, click Virtual Devices on the left hand side and then the New button on the far right to create a new AVD.

NOTE: When attempting to create a new AVD, if you are expecting to see available Targets but don't, it means you have not yet installed the SDK Platform Packages.  To do this, select the Available Packages on the left and then check the top level node in the window on the right to get all the available packages and then select Install Selected.

To make sure I'm covered with testing, I went ahead and created AVD's for each target (ex: Android2.1, Android1.6, ...) with a 64MB SD Card on them.