Android widget textview not updating

21 Feb

Instead IDs are added (that’s why we use ) or generated when the app is started.

Open activity_file and add android:id attribute to Text View using above example.

If we want to add something to a text displayed by Text View, we don’t need to get text first, modify it and set that text again. Of course we still need to refer to Text View element found via find View By Id().

This is a code: Instead of a specific string you could use a String variable or string resource as in the previous step.

Of course to make such an amazing Valentine’s app we could just modify a content of file, but let’s assume that firstly we want to show I’m the best and later change it to a new string.

There are many Android tutorials for developers, but it is difficult to find easy to understand lessons for beginners.

So in Java code we would use it too, but instead of attributes we will modify it by methods.

There are three scenarios: Now we focus only on scenario 1, leaving 2 & 3 for future lessons.

Mind that additional text would be glued exactly at the end of a current one, so usually it’s necessary to add a space at tge beggining, like ” More text”. So too see an effect you have to Summary: We could easily modify a text added in layout file.

If we now switch again to main_layot file and open a preview window (use Preview tab on the right edge of screen), we will still see I’m the best text. First we have to find right Text View tag using its ID and then use method set Text() to modify a text.