Habibi
Habibi

Reputation: 3

Get view created using inflater.inflate

I dont understand this. I cant setText() on view created using inflater.inflate()

val justView = inflater.inflate(R.layout.mybutton, null, false)
ayatList.addView(justView)
justView.setText("OK")

Upvotes: 0

Views: 52

Answers (1)

Ryan M
Ryan M

Reputation: 20137

You need to cast the result to TextView (assuming that that layout is just a TextView—note that Button is a type of TextView):

val justView = inflater.inflate(R.layout.mybutton, null, false) as TextView
ayatList.addView(justView)
justView.setText("OK")

Upvotes: 2

Related Questions