I’ve got a simple homescreen widget, which displays a list of items. Since I want to support older devices, instead of ListView I’m using a series of TextView objects that “emulate” ListView.
It works really well, but I’d like to assign a click listener for these items. In the listener I’d like to distinguish between them and take action depengind on item’s content.
How to do this? Since setOnClickPendingIntent takes view’s ID, I can’t assign separate intents for individual items – they all share the same ID, so the handler won’t know which item was tapped. I can instantiate RemoteViews only from XML layout, so I can’t add items with different ID’s (I’d need to create a lot of layout files, differing only by layout ID).
Since Honeycomb there is setOnClickFillInIntent method that deals with my problem in an acceptable way, but I can’t use it if I want my widget to work on Gingerbread.
Your widgets have to have unique IDs.
Sure you can. You have one layout file per app widget size (possibly, therefore, only one layout file period if you are only supporting one size). In that layout file, you give your widgets unique IDs.