-1

(i'm a software dev, but new to android development)

i have a edittext field on my layout on a activity. and i would like to set a text to it. this is fairly easy.

i lately i found out about viewBindings (vs. findViewById) and liked the idea.

so on onCreate i get my reference of the bindingobject (binding = ActivityMainBinding.inflate(getLayoutInflater())) and later on in another method (buttonclick) i use that to set the text: binding.txtSettingValue.setText("hello kitty") but the field in the running app actually show on screen dont change the value. even if i debug and look in the object itself - it changes and keep the value after the next click.

when that is done on a reference got by findViewById (even when i store that reference in the activity class and get that reference in onCreate) it works flawless.

what did i wrong?

thanks in advance

1 Answers1

0

i found it the fault:

in onCreate you usually use setContentView(..)

if you decide to use viewbindings instead of findviewbyid you should also setContentView to that layout root:

e.g. setContentView(binding.root)

instead of

setContentView(R.layout.activity_main)

now it works flawless :-D