title: Random items in ListView getting stuck at "Loading" in Android Widget
body: <p>In my App Activity, I am fetching data from GitHub API and storing it locally using Realm Database. Now in my App Widget, I am fetching that data from database and displaying it.</p>
  <p>The widget has a ListView. Now, whenever the widget loads up, some of the elements of the ListView gets displayed, but the rest are just stuck at &quot;Loading&quot;.</p>
  <p><a href="https://i.stack.imgur.com/C0ym9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/C0ym9.png" alt="Screenshot" /></a></p>
  <p>My Code for AppWidgetProvider</p>
  <pre><code>class GidgetWidget : AppWidgetProvider() {
  override fun onUpdate(
      context: Context,
      appWidgetManager: AppWidgetManager,
      appWidgetIds: IntArray
  ) {
      for (appWidgetId in appWidgetIds) {
          updateAppWidget(
              context,
              appWidgetManager,
              appWidgetId,
          )
      }
      super.onUpdate(context, appWidgetManager, appWidgetIds)
  }
  
  override fun onEnabled(context: Context) {}
  
  override fun onDisabled(context: Context) {}
  
  override fun onDeleted(context: Context?, appWidgetIds: IntArray?) {}
  }
  
  internal fun updateAppWidget(
     context: Context,
     appWidgetManager: AppWidgetManager,
     appWidgetId: Int,
  ) {
  val views = RemoteViews(context.packageName, R.layout.gidget_widget)
  
  val clickIntent = Intent(context, GidgetWidget::class.java)
  val clickPendingIntent = PendingIntent.getBroadcast(context, 0, clickIntent, 0)
  views.setPendingIntentTemplate(R.id.appwidgetListView, clickPendingIntent)
  
  val serviceIntent = Intent(context, WidgetRepoRemoteService::class.java)
  serviceIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId)
  views.setRemoteAdapter(appWidgetId, R.id.appwidgetListView, serviceIntent)
  
  appWidgetManager.updateAppWidget(appWidgetId, views)
  appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, R.id.appwidgetListView)
  </code></pre>
  <p>}</p>
  <p>My code for RemoteViewsService</p>
  <pre><code>class WidgetRepoRemoteService : RemoteViewsService() {
  override fun onGetViewFactory(intent: Intent?): RemoteViewsFactory {
      println(&quot;onGetViewFactory&quot;)
      return WidgetRepoRemoteViewsFactory(applicationContext, intent!!)
  }
  }
  </code></pre>
  <p>My Code for RemoteViewsFactory</p>
  <pre><code>class WidgetRepoRemoteViewsFactory(
     private val context: Context,
     intent: Intent,
  ) :
  RemoteViewsService.RemoteViewsFactory {
  private var dataSource: MutableList&lt;AddToWidget&gt; = mutableListOf()
  private var appWidgetId = 0
  
  init {
      appWidgetId = intent.getIntExtra(
          AppWidgetManager.EXTRA_APPWIDGET_ID,
          AppWidgetManager.INVALID_APPWIDGET_ID
      )
  }
  
  override fun onCreate() {
      //adding static data
      val temp = AddToWidget()
      temp.username = &quot;asdoasd&quot;
      temp.name = &quot;asdoaksd&quot;
      temp.avatarUrl = &quot;https://avatars.githubusercontent.com/u/15610556?&quot;
      temp.message = &quot;random message&quot;
      temp.date = &quot;today&quot;
      temp.icon = R.drawable.ic_github_issue
      dataSource.add(temp)
  }
  
  override fun onDataSetChanged() {
      //fetching data from database
      val realm: Realm = Realm.getDefaultInstance()
      val result = realm.where(AddToWidget::class.java).findAll()
  
      dataSource = result
  }
  
  override fun onDestroy() = dataSource.clear()
  
  override fun getCount(): Int = if (dataSource.size &lt;= 10) dataSource.size else 10
  
  @RequiresApi(Build.VERSION_CODES.O)
  override fun getViewAt(position: Int): RemoteViews {
      val views = RemoteViews(context.packageName, R.layout.appwidget_recycler_item)
      val currentItem = dataSource[position]
  
      views.setTextViewText(R.id.appwidgetRecyclerViewItemUsername, currentItem.username)
      views.setTextViewText(R.id.appwidgetRecyclerViewItemRepoName, currentItem.name)
      views.setTextViewText(R.id.appwidgetRecyclerViewItemMessage, currentItem.message)
      views.setTextViewText(R.id.appwidgetRecyclerViewItemDate, currentItem.date)
  
      val profilePhotoBitmap: Bitmap = Picasso.get().load(currentItem.avatarUrl).get()
      views.setImageViewBitmap(R.id.appwidgetRecyclerViewItemProfilePhoto, profilePhotoBitmap)
  
      views.setImageViewResource(R.id.appwidgetEventTypeIcon, currentItem.icon!!)
  
      val fillIntent = Intent()
      views.setOnClickFillInIntent(R.id.appwidgetRecyclerViewItemUsername, fillIntent)
  
      return views
  }
  
  override fun getLoadingView(): RemoteViews? {
      return null
  }
  
  override fun getViewTypeCount(): Int = 1
  
  override fun getItemId(position: Int): Long = position.toLong()
  
  override fun hasStableIds(): Boolean = true
  }
  </code></pre>
  <p>Any help would be much appreciated!</p>