简体   繁体   中英

Android Widget: setSelection on ListView

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM