Reputation: 1842
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.
Upvotes: 0
Views: 264
Reputation: 1354
You might be able to! I had the same issue, but then I realized that I was generating the rows (individual rows within a layout, each row from the same template) one at a time. Each row was its own RemoteViews, so within that for loop, I set the intent on itself. For example, if I'm adding new innerRemoteViews to outerRemoteViews, I'd call:
innerRemoteViews.setOnClickPendingIntent(R.id.inner_row_template_id, PendingIntent.getActivity(context, 0, intent, 0));
This way, the Intent gets added to the innerRemoteViews, where the id is still specific to that row.
Upvotes: 0
Reputation: 1006664
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.
Your widgets have to have unique IDs.
I can instantiate RemoteViews only from XML layout, so I can't add items with different ID's
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.
Upvotes: 1