1

I realize, if there is only 1 item in home widget list view, there will be flickering issues, if we perform

appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, android.R.id.list_view);

Note that, if there is 2 or more items in the home widget list view, the problem will gone ?!

Note, I had resize the widget to 4x4. (Size doesn't matter. Even flickering can be observed even I were using 4x2)

I use WeatherListWidget as example

In https://android.googlesource.com/platform/development/+/master/samples/WeatherListWidget/src/com/example/android/weatherlistwidget/WeatherDataProvider.java

If we were changing

sData.add(new WeatherDataPoint("Monday", 13));
sData.add(new WeatherDataPoint("Tuesday", 1));
...
sData.add(new WeatherDataPoint("Sunday", 27));

to single

sData.add(new WeatherDataPoint("Monday", 13));

flickering problem can be easily seen. (By pressing refresh button on top right)

If I look carefully, I suspect I saw "Loading..." text in between as described in

Homescreen widget, listView shows "Loading"

May I know why the problem only happen when there is 1 list view item? Is there any workaround to overcome this?

Community
  • 1
  • 1
Cheok Yan Cheng
  • 47,586
  • 132
  • 466
  • 875

3 Answers3

2

I have same problem. You can use following methods. First,declare RemoteView Instance in your class.

RemoteViews rv;

Second,in getViewAt(int position),you create an instance by new RemoteView().

@Override
public RemoteViews getViewAt(int position) {
    ...
    rv = new RemoteViews(mContext.getPackageName(), R.layout.grid_view_item);
    ...
}

Third,in getLoadingView() reuse instance rv.

@Override
public RemoteViews getLoadingView() {
        return rv;
}

And default loading view "show loading" will disappear,because you use rv as loading view.

yang david
  • 21
  • 2
0

I know this is old but I was able to work around the flicker when there was just one item in the list by reusing the same RemoteViews instance for the first item in the list AND the "loading view" by overriding getLoadingView() to return it as well.

0

You can remove flickering by using AppWidgetManager directly from your code instead of sending broadcast with ACTION_APPWIDGET_UPDATE.

First you need to get ids of your widget instances. Then to reuse code just create instance of YourAppWidgetProvider and call its onUpdate() method.

    int[] ids = appWidgetManager.getAppWidgetIds(
                    new ComponentName(context, YourAppWidgetProvider.class));

    YourAppWidgetProvider provider = new YourAppWidgetProvider();
    provider.onUpdate(context, appWidgetManager, ids);

It's not the cleanest solution but it'll remove the flickering effect.