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
2
Answers
You are not using the initialized
view
variable. Usebinding.root
insidesetContentView
like this:Make sure you are sending data on correct way,
remember use the same name of your key string,
and use Binding:
setContentView(view)