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.

Monday, July 25, 2011

Spotify - What's great and what's missing

UPDATE:  Since I originally wrote this, they have since added everything in the "What's missing" list except for browsing a genre.  Google All Access Music seems to do this better but I am still loving Spotify due to the integration into the iPhone and my Onkyo receiver at home.

I finally sank my teeth into the now US enabled Spotify music streaming service. My initial impression is that Spotify will soon make all other music services irrelevant especially with a few small tweaks.

Let's start with what they got right:
1) Access to basically any music any time you want.
2) The ability to subscribe to your friends play lists and even collaborate on play lists
3) The ability to directly recommend a song or album to a friend
4) How easy it is to find new music and listen to the full album right away
5) Synchronize everything between your mobile device and your desktop

What it's missing:
1) The ability to choose a song or artist and generate a smart playlist that will contain a variety of music like what you have chosen
2) The ability to pick a genre and listen to it as if it where a radio station
3) The ability to browse genres to find music

Some nice to haves:
1) Multilevel grouping of play lists
2) Some sort of conversation element between friends
3) "Subscribing" to an artist to be alerted of upcoming album releases and concerts in your area

If the missing items come to be, it will instantly render all other music services useless and irrelevant.

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

Thursday, June 3, 2010

Android Task Killer Apps Are A Disgrace

Stop using task killer apps people!

Using a task killer destablizes your device and the apps running on it. If you randomly kill your running apps and wonder why you see weird behavior on your device you should be beaten.

With the current powerhouse devices on the market, there is no need to free memory or whatever reason you give to doing this.

If using a task killer has helped you in some way, it's only because you have one or more apps that aren't configured well (ie, sync data very often) and/or is just poorly designed and should be uninstalled. Fix the cause, not the symptom.

I currently run without a task killer on a Droid Incredible using the Seido 1750 extended battery and get equal or better battery life then I did on my iPhone. After heavy use which includes an hour of listening to music, regular to heavy web browsing, downloading at least 5 apps, refreshing Google reader and twitter feeds many times, streaming a 5 minute flash video, and other normal activities I made it the entire day with over 40% of my battery left at the end. (If your aren't seeing this type of battery performance, see my previous post on fixing your battery problem)

Bottom line, please stop using these task killer apps and let the Android system do what it was intended to do. Otherwise you just give the Android platform a bad name.

Wednesday, June 2, 2010

Android Battery Life Fix

To all my Android brethren out there I would like to share a fix for the battery life woes I have been experiencing. I got my HTC Incredible a few weeks back and have been struggling to get the battery life the way I think it should be.

It appears there is a software glitch that is preventing the battery from reaching a full charge. If you turn the phone off to charge, it bypasses this and actually charges the phone fully. What I usually do is charge it with the phone on overnight then turn the phone off in the morning while I get ready to make sure it reaches full charge. (I usually do two or three cycles to make sure)  Hopefully Verizon/Google will issue an OTA update to fix this very soon!!

In addition to that you may also be able to squeeze a little extra life by turning off the Always On Mobile Data setting.  It's very simple and you should see an slight improvement. Just go to the following setting and unceck the option. This setting appears to tell your phone to maintain a data connection all the time instead of only when it needs it.

Menu -> Settings -> Wireless & networks -> Mobile networks -> Enable always-on mobile data (turn this off)

Regardless of the tricks you use, if you are concerned with your battery life, I would immediately download both JuicePlotter and SpareParts.  These apps will help you identify the activities and apps that are draining your battery life so you can tune it to fit your lifestyle.

Happy Androiding.

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.