You name it, it's fair game here: Android development, Windows, C#, Java, my pet, Video Games, Xbox, and Twitter. This is where I dump bits that may be helpful. Or not.

Saturday, April 24, 2010

AllredHouse.com is the new blog site

I have moved my blog to http://www.allredhouse.com/ - check it out!

Tuesday, April 13, 2010

Android Layout findViewById Returns Null

Every once in a while you run across a coding issue that has occurred in the past but you can't remember the resolution. Tonight is one of those times and the issue was an Android Layout one.

I had a layout xml file with the following id on a TextView:


id="@+id/foo"




In the OnCreate() method I set the content view:

setContentView(R.layout.my_main);

And then went to get the TextView as such:

TextView foo = (TextView) this.findViewById(R.id.foo);

The problem is, foo is always null.

The issue here is that you must use the correct schema for the id node, which I'm guessing is compiling correctly due to some past version compatibility "feature" in the Android code. Simply making the change to use android:id as shown below, made the null an issue of my past (again) and now I can move on to using the TextView any way I like.



Every once in a while you run across a coding issue that has occurred in the past but you can't remember the resolution. Tonight is one of those times and the issue was an Android Layout one.

I had a layout xml file with the following TextView:

android:id="@+id/foo"