Two things:
views.setScrollPosition(R.id.lvWidget, 3);
is the correct call. Internally, setScrollPosition(int, int)
calls RemoteViews#setInt(viewId, "smoothScrollToPosition", position);
.
viewId : your ListView's id
"smoothScrollToPosition" : method name to invoke on the ListView
position : position to scroll to
So, you are calling the correct method.
Following is a comment for the method AppWidgetManager#partiallyUpdateAppWidget(int, RemoteViews)
- taken from the source code of AppWidgetManager.java
. I believe it answers your question: ... Use with {RemoteViews#showNext(int)}, {RemoteViews#showPrevious(int)},{RemoteViews#setScrollPosition(int, int)} and similar commands...
/**
* Perform an incremental update or command on the widget specified by appWidgetId.
*
* This update differs from {@link #updateAppWidget(int, RemoteViews)} in that the RemoteViews
* object which is passed is understood to be an incomplete representation of the widget, and
* hence is not cached by the AppWidgetService. Note that because these updates are not cached,
* any state that they modify that is not restored by restoreInstanceState will not persist in
* the case that the widgets are restored using the cached version in AppWidgetService.
*
* Use with {RemoteViews#showNext(int)}, {RemoteViews#showPrevious(int)},
* {RemoteViews#setScrollPosition(int, int)} and similar commands.
*
* <p>
* It is okay to call this method both inside an {@link #ACTION_APPWIDGET_UPDATE} broadcast,
* and outside of the handler.
* This method will only work when called from the uid that owns the AppWidget provider.
*
* <p>
* This method will be ignored if a widget has not received a full update via
* {@link #updateAppWidget(int[], RemoteViews)}.
*
* @param appWidgetId The AppWidget instance for which to set the RemoteViews.
* @param views The RemoteViews object containing the incremental update / command.
*/
public void partiallyUpdateAppWidget(int appWidgetId, RemoteViews views) {
partiallyUpdateAppWidget(new int[] { appWidgetId }, views);
}
As the comment indicates, call partiallyUpdateAppWidget(appWidgetId, views)
after views.setScrollPosition(R.id.lvWidget, 3)
.
The comment also warns you: This method will be ignored if a widget has not received a full update via {#updateAppWidget(int[], RemoteViews)}
. This might mean that the following calls:
views.setRemoteAdapter(R.id.lvWidget, svcIntent);
views.setScrollPosition(R.id.lvWidget, 3);
should not be made in one update. I suggest that you break these calls into two separate updates:
First:
views.setRemoteAdapter(R.id.lvWidget, svcIntent);
mAppWidgetManager.updateAppWidget(appWidgetIds, views);
Second:
views.setScrollPosition(R.id.lvWidget, 3);
mAppWidgetManager.partiallyUpdateAppWidget(appWidgetId, views);
Note that the first one is a full update, while the second one is only partial.