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