setReverseLayout
and setStackFromEnd
are both functions on the LinearLayoutManager
class, not the base LayoutManager
one. So you have to make sure the variable you're referencing has a LinearLayoutManager
type (or cast it):
// implicitly setting the type to the class you're constructing
val layoutManager = LinearLayoutManager(this)
// or you can just specify it explicitly
val layoutManager: LinearLayoutManager = LinearLayoutManager(this)
// now you can configure that object, and set it on the RecyclerView
layoutManager.setReverseLayout(true)
studentRecyclerView.layoutManager = layoutManager
studentRecyclerView.layoutManager
's type is just the base LayoutManager
(so you can provide different implementations of a layout manager), so if you read that property you'll just get a LayoutManager
. If you wanted to treat it as a LinearLayoutManager
specifically (and access the functions and properties on that type), you'd have to cast it:
studentRecyclerView.layoutManager = LinearLayoutManager(this)
...
(studentRecyclerView.layoutManager as LinearLayoutManager).setReverseLayout(true)
This is messy though, and it's usually better to just hold your own reference with the correct type - no need to complicate things, especially during a simple setup block!
And because it's Kotlin, set*
functions can be written as a property (e.g. layoutManager.reverseLayout = true
) and the IDE will offer to change the function version to the property version, if appropriate. Same thing though, just a different way of writing it.