Android example of updating textview did he change his mind dating
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.The easiest way to find element of the Android app layout is to use its ID. As you remember @ means that we refer to resources, then we give resource type and after slash resource name (@).
Put this line after: set Content View(R.layout.activity_main).
This line displays on device screen layout resource – in this case activity_file.
By the way maybe you have noticed that adding this code also resulted in a new line in import section at the top of Main file: Import is used to add predefined Android or Java classes from other packages, but we don’t have to bother about it as Android Studio adds import lines automatically as we start to use some classes. Now we have to assign Text View from layout file to Text View variable.
Mind that this would completely replace an original text.
Of course instead of using the text directly into a code we rather should refer to string resources as explained in previous lesson.