I'm trying to make the listrows in my ListView Widget clickable by using the setOnClickFillInIntent
method but whenever I click a ListItem nothing happends. Here are some key parts of my code:
Intent i = new Intent();
Bundle extras = new Bundle();
extras.putInt(Resource.WIDGET_PACKAGE, position);
i.putExtras(extras);
row.setOnClickFillInIntent(R.id.widget_layout_parent, i);
This is at the end of getView()
in my ViewFactory. Resource.WIDGET_PACKAGE contains my package name and is just like any other key. The position int is from the getView()
parameters. R.id.widget_layout_parent
is the parent layout in all of the list items.
Here's the end of my WidgetProviders onUpdate()
Intent clickIntent = new Intent(context, ItemListActivity.class);
PendingIntent clickPI = PendingIntent.getActivity(context, 0,
clickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
widget.setPendingIntentTemplate(R.id.widget_layout_parent, clickPI);
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds[i],
R.id.widget_list_view);
Is there something I'm missing or is there anything else you'd like to know?
All help is appreciated! :)
When you call setPendingIntentTemplate(...)
, the id
should be that of the AdapterView (in this case the ListView). When you call setOnClickFillInIntent(...)
, the id
should be that of the root View of the item layout, whcih is what you are already doing if I read your original post correctly.
public void onUpdate(Context context, AppWidgetManager manager, int[] appWidgetIds) {
/* ... */
widget.setPendingIntentTemplate(R.id.appwidget_listview, clickPI);
/* ... */
}
public RemoteViews getViewAt(int position) {
/* ... */
row.setOnClickFillInIntent(R.id.widget_layout_parent, intent);
/* ... */
return row;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With