How to access LayoutManager from RecyclerView.Adapter to get scrollToPosition? : <p>I customized <code>RecyclerView</code> by adding separate layouts for header and footer. I created constants to determine the property of header, footer and list item in the adapter class. I also created a ViewHolder pattern and assign the layouts to be shown based on the view type. I fixed the header at zeroth position and footer at last position of the array by override <code>getItemViewType</code> method.</p>

<p>I want to make the footer element clickable, so I assign a <code>setOnClickListener(new View.OnClickListener())</code> and overwrote <code>onClick(view: View)</code></p>

<p>My goal is to click on the footer and <code>scrollToPosition</code> 0 or 1 (0 = Header, 1 = first item element). </p>

<p>That's MyAdapter definition:</p>

<pre><code>class MyAdapter(context: Context, data: Array[String]) extends RecyclerView.Adapter[RecyclerView.ViewHolder]

...

override def onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int): Unit = holder match {
  ...
  case holder:FooterViewHolder =&gt;
    holder.backToTop.setOnClickListener(new View.OnClickListener() {
      override def onClick (view: View) {
        backToTop(???)
        Toast.makeText (context, "Clicked Footer", Toast.LENGTH_SHORT).show()
      }
    })
  ...
}
...
</code></pre>

<p>I read I just need to do this: <code>recyclerView.getLayoutManager().scrollToPosition(position)</code></p>

<p>Unfortunately I can't access the LayoutManager from my Adapter class. Any ideas what I can do?</p>
