Question

So I'm developing my first Android Widget, consisting primarily of a ListView. I'm using a RemoteViewsFactory to populate the list view, which works fine, but I'm having trouble defaulting the selected index of the list.

Normally ListView#setSelection works fine, but in this case (using RemoteViews) it doesn't seem to do anything at all.

I'm sure this is the wrong place to be doing it, but in AppWidgetProvider#onUpdate I'm doing the following:

 RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.widget);
 widget.setRemoteAdapter(R.id.widget_list, svcIntent);

 Log.i(TAG, "Setting selection: " + position);
 widget.setInt(R.id.widget_list, "setSelection", position);

I'm assuming it's not working because the list hasn't been populated yet, due to the async nature of collection views, but I'm not sure where else I can even put it.

The goal is that the first time the user sees the widget, before interacting with it, and any time the list changes (hourly), the list is scrolled to a specific item.

Any help would be appreciated!

Was it helpful?

Solution

widget.setScrollPosition(R.id.widget_list, position);

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top