Android Patterns

I just came across this Android Patterns site. And I love it.

New Android Game

I made a fun game of memory. You have to pair up the cards as quickly as possible. See who can get the fastest score. So far my high score is 60 some seconds.

BadTokenException for Dialog

I went to add a Dialog in a game that I am working on and encountered a BadTokenException. I initially thought that it was related to the library I was using for the game. Then I realized I was using an application context instead of an activity context(which is required for dialogs). For some reason the android documentation has an …

java.net.UnknownHostException:

While programming I kept getting dns failed exceptions. The error was called due to not having the proper permission for using the internet in my android manifest. <uses-permission android:name="android.permission.INTERNET" />

Lazy Loading GridView

I just added sample code showing one method of lazy loading images in a GridView. I used thread, handler, and the looper classes. It starts by displaying a GridView with a ViewSwitcher that initially displays ProgressBars for each image. Then as the images are sequentially loaded the ViewSwitcher switches to the loaded ImageView. Check it out here. Screen shot:

getAdapter throwing java.lang.ClassCastException

I had used addHeaderView method to add a header to my listview. But when I went to retrieve my adapter I kept getting class cast exceptions. I was very mystified until I looked at my recent changes. I commented out the addheaderview line and viola it worked. A bit of googling directed me to this useful link about the topic.

Custom ListView Layout

I came across this while trying to figure out how to make a custom list view layout. So far it works really well. Very simple straight forward example.

notifyDataSetChanged not working for ListView with CursorAdapter

I was running into problems where my ListView was not updating after calls to notifyDataSetChanged. Despite the Cursor.isOpen returning true, calls to Cursor.requery were throwing Cursor already closed exceptions. I don’t know why this is but just using changeCursor worked! Additional information.

Dialog setOnClickListener not working

When making a dialog subclass I came across a problem where OnClickListener events were not firing. The solution I found here worked. It just entailed moving the onclick listener assignments from the normal Oncreate method to the onStart method.