title: Android Paging v3 with just local Room database: how do I scroll to specific position in a paged list?
body: <p>I'm not sure if this is the correct use case for <a href="https://developer.android.com/topic/libraries/architecture/paging/v3-paged-data" rel="nofollow noreferrer">Paging v3</a> but here goes.</p>
  <p>All my data is in a local Room database (no network calls, no APIs). I have a potentially large data set of todo-lists (one for each date). I have a RecyclerView that displays these todo-lists to the user. Obviously, I don't want to load all the todo-lists for the user so I chose to go with a paged data source and decided to use Paging v3.</p>
  <p>I followed <a href="https://www.youtube.com/watch?v=BwUblMTiUo8" rel="nofollow noreferrer">this youtube tutorial</a> for my paging implementation.</p>
  <p><strong>I got everything working for a basic use case, but now I'm stuck. I want to let the user jump to a specific date in the list. I also want to listen if they scroll to a new date and create a new todo-list for them.</strong></p>
  <p>I'm not sure how to scroll my RecyclerView or paged source to a specific point in the list.</p>
  <p>My Dao:</p>
  <pre><code>    @Transaction
      @Query(&quot;SELECT * FROM todo_list ORDER BY date DESC&quot;)
      fun loadTodoListsPaged(): PagingSource&lt;Int, TodoList&gt;
  </code></pre>
  <p>My View Model:</p>
  <pre><code>class TodoListViewModel(application: Application) : AndroidViewModel(application) {
  
      val todoListsPaged = Pager(PagingConfig(
              pageSize = 10,
              enablePlaceholders = false,
              maxSize = 30
      )) {
          myTodoListDao.loadTodoListsPaged()
      }.flow.cachedIn(viewModelScope)
  }
  </code></pre>
  <p>My Adapter:</p>
  <pre><code>class TodoListPagingDataAdapter(
      val context: Context
  ): PagingDataAdapter&lt;TodoList, TodoListViewHolder&gt;(TodoListDiffUtilCallback()) {
  
  ...
  
  }
  </code></pre>
  <p>I'm not sure if this is possible because <code>Room only supports PagingSource with Key of type Int.</code></p>
  <p><strong>Using <a href="https://developer.android.com/topic/libraries/architecture/paging/v3-paged-data" rel="nofollow noreferrer">Paging v3</a>, how do I jump or scroll to a specific point in the list?</strong></p>
  <p>Ideally, I'd just pass something the date and it would tell me the page I need. Then I pass the page to the adapter/recyclerview/pager and it loads it for me.</p>
  <p><strong>Update</strong></p>
  <p>I just ended up storing a mutable list of dates as LiveData and used a Transformation Switch Map to map that to my todo lists (passing in the list of dates to the database and getting associated lists back). As the user scrolls, I add/remove dates from this mutable list and it automatically updates. It worked a lot better than the paging and was much more simple. If anyone wants more details, just ask.</p>