Give TextView a variable

I’m trying to set a text on a TextView using a val

class shoeDetails : AppCompatActivity() {
private lateinit var binding: ActivityShoeDetailsBinding
override fun onCreate(savedInstanceState: Bundle?) {
    binding = ActivityShoeDetailsBinding.inflate(layoutInflater)
    val view = binding.root

 val title =   intent.getStringExtra("Title")
 val model =   intent.getStringExtra("Model")
 val kmused = intent.getStringExtra("KmUsed")?.toFloat()
 val kmestimated =   intent.getStringExtra("KmEstimated")?.toFloat()

    binding.textView12.text = model
    binding.textView10.text = title
    binding.textView15.text = kmused.toString()
    binding.textView16.text = kmestimated.toString()

When I print on console the values are arriving, but the text never changes on the UI

>Solution :

You are not using the initialized view variable. Use binding.root inside setContentView like this:


Leave a Reply