Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?) {
    super.onCreate(savedInstanceState)
    binding = ActivityShoeDetailsBinding.inflate(layoutInflater)
    val view = binding.root
    setContentView(R.layout.activity_shoe_details)

 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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

setContentView(binding.root)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading