
Then fill this template every time a new RemoteViews object is created by the RemoteViewsFactory.Īdd this code in getViewAt method in MyWidgetRemoteViewsFactory class. widgetListView, clickPendingIntentTemplate ) įor each ListView item we are launching DetailsActivity which will simply display the task description sent as an extra. addNextIntentWithParentStack (clickIntentTemplate ). class ) PendingIntent clickPendingIntentTemplate = TaskStackBuilder.

Add this code in onUpdate method in CollectionAppWidgetProvider class after tRemoteAdapter(R.id.widgetListView, intent) // template to handle the click listener for each item Intent clickIntentTemplate = new Intent (context, DetailsActivity. It requires some additional steps.įirst you need to setup a template for PendingIntent.
/userfiles/images/app-test.jpg)
Click events on ListView itemsĪdding click events on ListView items is not as simple as setting up the setOnItemClickListener on the ListView object. But as widgets run in a different context, we need to register the click event through a PendingIntent. The idea here is similar to how we add click events in our apps. public class MyWidgetRemoteViewsFactory implements RemoteViewsService. Create a new Java class, name it MyWidgetRemoteViewsFactory, and set it to implement the class RemoteViewsService.RemoteViewsFactory.

An adapter is used to connect the collection items(for example, ListView items or GridView items) with the data set. RemoteViewsFactory serves the purpose of an adapter in the widget’s context.
