skip to Main Content

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


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

    setContentView(binding.root)
    
    Login or Signup to reply.
  2. Make sure you are sending data on correct way,
    remember use the same name of your key string,
    and use Binding:

    setContentView(view)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search