Home > Enterprise >  Can't set layout manager on the recycler view
Can't set layout manager on the recycler view

Time:12-26

I was trying to call the recycler view in the main activity kotiln file but even after doing all the steps correctly android studio showed an error

I am trying to set layout manager to the recycler view

CodePudding user response:

first, you have to define and initialize your recyclerView. so add this to the global scope

private lateinit var rvMaps : RecyclerView

then add this in the onCreate function

rvMaps = findViewById(R.id.rvMaps)

rvMaps.layoutManager

CodePudding user response:

First you Have to defined the recycler view and after that you have to initialize that view with the help of findviewbyId. so your MainActivity code will be look like this.

   class MainActivity : ComponentActivity() {

         private lateinit var rvMaps : RecyclerView

           override fun onCreate(savedInstanceState: Bundle?) {
               super.onCreate(savedInstanceState)
               setContentView(R.layout.activity_main)

               rvMaps = findViewById(R.id.rvMaps)
               rvMaps.layoutManager  //Add layout manager
       }
    }
  • Related