WepsTech
The world of development
Typically, you don’t ever need to directly use a LayoutInflater
. Android does most of the layout inflation for you when you call setContentView()
in the onCreate()
method of your activity. So you, as the programmer, are responsible for making sure the views are inflated. Now you want to inflate views in the context of a ListView
. The Adapter class can do the inflation for you if you do not want to customize each item. But if you want to customize the views shown in a list, you will have to manually inflate each view with the LayoutInflater, since there is no other existing method you can use. But if you are here then in very simple way we can use like below code
.
fun inflaterData() {
val inflater: LayoutInflater = this@LocationInfoActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val viewGroup : ViewGroup = findViewById (R.id.linear_layout)
viewGroup!!.removeAllViews()
for (i in 0 until list.size) {
val model = list[i]
val view : ViewGroup = inflater.inflate(R.layout.item_for_view, viewGroup, false) as ViewGroup
val tvTitle : TextView = view.findViewById (R.id.tvTitle)
tvTitle.text = model.label
view.tag = i
view.setOnClickListener { v ->
val index = v.tag as Int
Toast.makeText(applicationContext, index.toString(), Toast.LENGTH_LONG).show()
}
viewGroup.addView(view, i)
}
}
Wish you good luck 🙂 Happy Coding
gallant
Ԛuaⅼitʏ artiⅽles is the key to attract the users to pаy a visit
the site, that’s what this site iѕ providing.
jahrastafara
The short answer is the lack of lambdas and functional operations. But Kotlin can work with them, so sorting, transforming, mapping or filtering are just a function call away.
rooms anaheim
This is my first time pay a visit at here and i am actually impressed to read all
at alone place.
n95 respirator
Educative article, learned a lot. So glad I discovered
your blog, and was able to learn new things. Keep posting articles, it’s really
valuable.
Best regards,
Harrell Dencker
ปั้มไลค์
Like!! Really appreciate you sharing this blog post.Really thank you! Keep writing.
small business accounting
Good post. I learn something totally new and challenging on blogs I stumbleupon on a daily basis. It will always be useful to read through content from other authors and use something from other web sites.
best web hosting 2020
This information is worth everyone’s attention. When can I find
out more?
best web hosting company
My relatives always say that I am killing my time here at net, however I know I am getting knowledge
everyday by reading such pleasant articles.
adreamoftrains webhosting
Thank you for sharing your info. I truly appreciate your efforts and I
am waiting for your further post thank you once again. adreamoftrains web hosting services
Androidena
example requires a bit more work when we manually add the View to a ViewGroup. Adding our Button to our LinearLayout was more convenient with one line of code when
El Reloj Antiguo XVI
Wow, great blog. Want more.
tantric massage london
Thanks-a-mundo for the post.Thanks Again. Keep writing.