Search code examples
javaandroidandroid-appwidgetappwidgetproviderandroid-appwidget-list

Android AppWidget ListView won't populate


I’m having a hard time figuring out why my App Widget ListView won’t populate with data. Everything seems to be wired up right. When I debug, I can see the data that is being retrieved from my database (Firestore). However, it still won’t populate into the App Widget.

I created a new Issue on my Github to make it easier to view the problem:Github Issue

RemoteViewsFactory

  • The data is successfully retrieved from Firestore DB
  • List<Review> reviews is populated
  • The Review objects within it contain the right data
  • get() methods return the right data

ReviewsAppWidgetProvider

  • ReviewsWidgetService Intent is created
  • setRemoteAdapter() is called using the Intent and passing in the ListView as well
  • updateAppWidget() is called
  • notifyAppWIdgetViewDataChaged() is called

ReviewFragment

  • ReviewsAppWidgetProvider.updateAppWidgets() is called when adding or deleting reviews

AndroidManifest

  • ReviewsAppWidgetProvider declared as a reveiver
  • Intent Filter set for action.APPWIDGET_UPDATE
  • ReviewsWidgetService declared as Service
  • permssion BIND_REMOTEVIEWS set

Solution

  • As you said, everything is ok with fetching data. But it's still draw a loading view. So the problem is in your divider. View can't be used in app widgets, because launcher process doesn't know about view, it's only know about limited count of views, all views that can be used, you can find here.

    So how to make a such divider? Firstly you need a shape, so it will be something like bottom_border.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
        <stroke
            android:width="0.5dp"
            android:color="#CCCCCC" />
    </shape>
    

    So now in your root view add background bottom_border.xml like:

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:background="@drawable/bottom_border"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
            ...