1

I have a listview in the AppWidget. I would like to have the listview to start at specific position when user adds the listview to the home screen or after refreshing the widget. I tried to use the setScrollPostion, but it doesn't work.

e.g:

RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.my_widget);

......

views.setScrollPosition(R.id.listview_in_widget, 1000); appWidgetManager.updateAppWidget(appWidgetId, views);

The widget is still showing the first item.

I would appreciate it if anyone can give me some hints how to do it?

tshepang
  • 12,111
  • 21
  • 91
  • 136
David
  • 101
  • 1
  • 5

3 Answers3

1

So you should call setScrollPosition method like this:

views.post(new Runnable() {

    @Override
    public void run() {
        views.setScrollPosition(R.id.listview_in_widget, 1000);     
    }
});

or in views.postDelayed method.

Koso
  • 3,200
  • 2
  • 20
  • 22
  • I am sorry that there is no scrollto or setselection in remoteviews. Actually, I an trying to implement a circular listview in appwidget. I can do it in normal list view, as I can do setselection in normal listview. I am trying to implement a calendar appwidget on home screen so that users can scroll up and down. But I have problem to set the initial position of the remote list view. – David Jul 09 '13 at 01:16
  • Sorry I misunderstood you question at first, so I edited my answer, hope it helps you. – Koso Jul 09 '13 at 07:52
  • Is there any way to get the scroll position in an appwidget/remoteview? – Eric Cochran Sep 04 '13 at 17:12
  • Unfortunately, Nightly Nexus, I have been searching for a couple of hours on this matter and I couldn't find any way of determining listview scroll position through a remoteview of an appwidget. :( – cassi.lup Feb 07 '14 at 16:20
0

Yes this is possible for a Widget ListView. It took me a few weeks of intermittent attempts and tests, but this is what I've learned.

1) Widgets utilize RemoteViews and as a result can only use a subset of functionality of the normal view (ListView in this case). Go to the ListView source and do a search for @android.view.RemotableViewMethod. These annotations determine what a widget could end up using.

2) Check the RemoteViews source and notice on line 776 the isAnnotationPresent check. You'll often see an error logged in LogCat that hits this line when you make a method call that is not annotated with RemotableViewMethod.

3) You need to ensure you make an updateAppWidget call after invoking a method of your RemoteViews instance. Here is an example:

//update list item pos
RemoteViews remoteViews = new RemoteViews(_context.getPackageName(), R.layout.widget);
remoteViews.setScrollPosition(R.id.widget_nodes_list, newPos);

//apply pos
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(_context);
appWidgetManager.updateAppWidget(_appWidgetId, remoteViews);
dak
  • 89
  • 9
0

Please look at this question. Here is explained what to do, to get it working: Android RemoteViews ListView Scroll

Community
  • 1
  • 1
Wookiee
  • 139
  • 2
  • 12