Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 439 Vote(s) - 3.43 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can i set layoutmanager to RecycleView using kotlin

#1
How can i set layoutmanager to RecycleView using kotlin as java code below:

mRecyclerView.setLayoutManager(mLinearLayoutManager);
Reply

#2
You can do like this

val linearLayoutManager = LinearLayoutManager(this)
linearLayoutManager.orientation = LinearLayoutManager.VERTICAL
recyclerview!!.layoutManager = linearLayoutManager
recyclerview!!.isNestedScrollingEnabled = true
recyclerview!!.setHasFixedSize(true)
Reply

#3
Simply write this to set `LayoutManager`

// Define this globally
lateinit var recyclerView: RecyclerView

// Initialize this after `activity` or `fragment` is created
recyclerView = findViewById(R.id.recyclerView) as RecyclerView

recyclerView.setHasFixedSize(true)
recyclerView.layoutManager = LinearLayoutManager(activity!!) as RecyclerView.LayoutManager
Reply

#4
I had same issue, reason was I had initialize recyclerView as

var recyclerView = findViewById<View>(R.id.recycleView)

Make sure you initialize as below

var recyclerView = findViewById<View>(R.id.recycleView) as RecyclerView

Reply

#5
Apply plugin in your app build

apply plugin: 'kotlin-android-extensions'

For my case view id of `RecyclerView` is `my_recycler_view`.

In your java file write -

my_recycler_view.layoutManager = LinearLayoutManager(context)

By default `LinearLayoutManager(context)` will set vertical orientation, update it as per need.
Reply

#6
```recyclerView.layoutManager = LinearLayoutManager(context)
```

or

```recyclerView.layoutManager = GridLayoutManager(context, spanCount)
```
Reply

#7
You can set using this code:

binding.recyclerView.setHasFixedSize(true)
binding.recyclerView.layoutManager = LinearLayoutManager(this ,LinearLayoutManager.VERTICAL ,false)
binding.recyclerView.adapter = customAdapter(this ,getList())
Reply

#8
private var mRecyclerView: RecyclerView? = null

mRecyclerView?.layoutManager = LinearLayoutManager(activity)
Reply

#9
Following two lines sets ***orientation*** to ***vertical***

mRecyclerView.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL ,false)

OR

mRecyclerView.layoutManager = LinearLayoutManager(this)
mRecyclerView.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL ,false)

sets horizontal orientation

To set grid layout,

mRecyclerView.layoutManager = GridLayoutManager(this, spanCount)
Reply

#10
You can use

recyclerView.layoutManager = LinearLayoutManager(context) // default orientation is vertical

// if you want horizontal recyclerview
// recyclerView.layoutManager = LinearLayoutManager(this, RecyclerView.HORIZONTAL, false)

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through