title: How do I refresh a RecyclerView + PagedListAdapter and scroll to top?
body: <p>I have a <code>RecyclerView</code> that is using a <code>PagedListAdapter</code>.  I want to refresh the list (ie fetch the data from my <code>DataSource</code>) and scroll to the top automatically.</p>
  
  <p>Here's my RecyclerView:</p>
  
  <pre class="lang-xml prettyprint-override"><code>    &lt;android.support.v7.widget.RecyclerView
          android:id="@+id/recyclerView"
          android:layout_width="match_parent"
          android:layout_height="match_parent" /&gt;
  </code></pre>
  
  <pre><code>    val adapter by lazy {
          DiscoveryListAdapter(activity)
      }
  </code></pre>
  
  <pre><code>        recyclerView.let {
              it.adapter = adapter
              it.layoutManager = LinearLayoutManager(activity)
          }
  </code></pre>
  
  <p>Here's my Adapter:</p>
  
  <pre><code>class DiscoveryListAdapter() : PagedListAdapter&lt;Discovery, DiscoveryListItemViewHolder&gt;(DiscoveryDiffCallback()) {
  
      @SuppressLint("CheckResult")
      override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DiscoveryListItemViewHolder {
          //Extension function
          val view = parent.inflate(R.layout.discovery_detail_list_item)
          return DiscoveryListItemViewHolder(view)
      }
  
      override fun onBindViewHolder(viewHolder: DiscoveryListItemViewHolder, position: Int) {
          getItem(position)?.let {
              viewHolder.populateFrom(it)
          }
      }
  
      class DiscoveryDiffCallback : DiffUtil.ItemCallback&lt;Discovery&gt;() {
          override fun areItemsTheSame(one: Discovery, two: Discovery) =
                  one == two
  
          override fun areContentsTheSame(one: Discovery, two: Discovery) =
                  one == two
      }
  }
  </code></pre>
  
  <p>I'm building the PagedList like so, subscribing to the LiveData object that is returned and calling <code>submitList</code> on the adapter:</p>
  
  <pre><code>    fun buildLivePagedList(): LiveData&lt;PagedList&lt;Discovery&gt;&gt; {
          val config = PagedList.Config.Builder()
                  .setPageSize(PAGE_SIZE)
                  .setEnablePlaceholders(false)
                  .setPrefetchDistance(PAGE_SIZE * 2)
                  .build()
          val factory = DiscoveryListDataSourceFactory()
          return LivePagedListBuilder(factory, config).build()
      }
  </code></pre>
  
  <p>I am using this line to refresh the list:</p>
  
  <pre><code>adapter.currentList?.dataSource?.invalidate()
  </code></pre>
  
  <p>This seems to refresh correctly, but it leaves the list scrolled halfway down.  From there I don't know how to get the recyclerview to return to the top of the list.  I have tried <code>recyclerView.scrollToPosition(0)</code> but no dice. No matter what, the list refreshes but does not scroll to the top.  How do I do this?</p>