title: How to load items in android homescreen listview widget?
body: <p>I am currently developing an Android project which makes use of a Homescreen Widget to display data to the user. The view that I used in the Widget is a <code>ListView</code>. Below are my codes:</p>
  
  <p><strong>WidgetService Class</strong></p>
  
  <pre><code>public class WidgetService extends RemoteViewsService
  {
  
      @Override
      public RemoteViewsFactory onGetViewFactory(Intent intent)
      {   
          return (new WidgetRemoteViewsFactory(this.getApplicationContext(), intent));
      }
  
  }
  </code></pre>
  
  <p><strong>WidgetProvider Class</strong></p>
  
  <pre><code>public class WidgetProvider extends AppWidgetProvider
  {   
      @Override
      public void onDeleted(Context context, int[] appWidgetIds)
      {
          super.onDeleted(context, appWidgetIds);
      }
  
      @Override
      public void onDisabled(Context context) 
      {
          super.onDisabled(context);
      }
  
      @Override
      public void onEnabled(Context context) 
      {
          super.onEnabled(context);
      }
  
      @Override
      public void onReceive(Context context, Intent intent)
      {
          super.onReceive(context, intent);
      }
  
      @Override
      public void onUpdate(Context context, AppWidgetManager appWidgetManager,
              int[] appWidgetIds) 
      {
          for(int i=0;i&lt;appWidgetIds.length;i++)
          {
              RemoteViews rv = new RemoteViews(context.getPackageName(),
                      R.layout.widget);
  
              Intent intent = new Intent(context, WidgetService.class);
              intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
                      appWidgetIds[i]);
              intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
  
              rv.setRemoteAdapter(R.id.widgetListView, intent);
  
              appWidgetManager.updateAppWidget(appWidgetIds[i], rv);
          }
          super.onUpdate(context, appWidgetManager, appWidgetIds);
      }
  }
  </code></pre>
  
  <p><strong>WidgetRemoteViewsFactory Class</strong></p>
  
  <pre><code>public class WidgetRemoteViewsFactory implements RemoteViewsFactory
  {
  private Context context = null;
  private int appWidgetId;
  
  private List&lt;String&gt; widgetList = new ArrayList&lt;String&gt;();
  private DBHelper dbhelper;
  
  public WidgetRemoteViewsFactory(Context context, Intent intent)
  {
      this.context = context;
      appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
              AppWidgetManager.INVALID_APPWIDGET_ID);
      Log.d("AppWidgetId", String.valueOf(appWidgetId));
      dbhelper = new DBHelper(this.context);
  }
  
  private void updateWidgetListView()
  {
      String[] widgetFruitsArray = dbhelper.retrieveFruitsList();
      List&lt;String&gt; convertedToList = new ArrayList&lt;String&gt;(Arrays.asList(widgetFruitsArray));
      this.widgetList = convertedToList;
  }
  
  @Override
  public int getCount()
  {
      return widgetList.size();
  }
  
  @Override
  public long getItemId(int position)
  {
      return position;
  }
  
  @Override
  public RemoteViews getLoadingView()
  {
      // TODO Auto-generated method stub
      return null;
  }
  
  @Override
  public RemoteViews getViewAt(int position)
  {
      Log.d("WidgetCreatingView", "WidgetCreatingView");
      RemoteViews remoteView = new RemoteViews(context.getPackageName(),
              R.layout.listview_row_item);
  
      Log.d("Loading", widgetList.get(position));
      remoteView.setTextViewText(R.id.listTV, widgetList.get(position));
  
      return remoteView;
  }
  
  @Override
  public int getViewTypeCount()
  {
      // TODO Auto-generated method stub
      return 0;
  }
  
  @Override
  public boolean hasStableIds()
  {
      // TODO Auto-generated method stub
      return false;
  }
  
  @Override
  public void onCreate()
  {
      // TODO Auto-generated method stub
      updateWidgetListView();
  }
  
  @Override
  public void onDataSetChanged()
  {
      // TODO Auto-generated method stub
      updateWidgetListView();
  }
  
  @Override
  public void onDestroy()
  {
      // TODO Auto-generated method stub
      widgetList.clear();
      dbhelper.close();
  }
  }
  </code></pre>
  
  <p><strong>Android Manifest File</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.listviewwithdb"
  android:versionCode="1"
  android:versionName="1.0" &gt;
  
  &lt;uses-sdk
      android:minSdkVersion="14"
      android:targetSdkVersion="19" /&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/MyTheme.Light" &gt;
  
      &lt;activity
          android:name="com.example.listviewwithdb.MainActivity"
          android:label="@string/app_name" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  
      &lt;receiver android:name="com.example.listviewwithdb.WidgetProvider" &gt;
          &lt;intent-filter &gt;
              &lt;action 
                  android:name="android.appwidget.action.APPWIDGET_UPDATE" /&gt;
          &lt;/intent-filter&gt;
  
          &lt;meta-data
              android:name="android.appwidget.provider"
              android:resource="@xml/widgetinfo" /&gt;
      &lt;/receiver&gt;
  
      &lt;service
          android:name="com.example.listviewwithdb.WidgetService"
          android:exported="false"
          android:permission="android.permission.BIND_REMOTEVIEWS" /&gt;
  
  &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>The problem is that I can add the widget into the homescreen, but it displays the list of item in the listview with a "Loading.." message in it, I tried logging the values at <code>getViewAt()</code> as shown above and it displays the content that I want successfully. Is there anything that I'm missing in my codes that is causing the issue? Thanks for the help in advance </p>