How To Print Message In An Android App
Solution 1:
Based on the tutorial you were following it appears as if you are generating just a blank layout resource file which by default populates with the static value of "Hello World". In order to manipulate this value with the String resource you created you will need to adjust the Layout file where the Textview is being stored.
Now based on your code you would need to edit the android:text section of your Layout file. I generated a string very similar to yours however I edited the resource file above to set the text properly. Now you can see the value updated with the custom string I implemented.
Any time you are referencing a String resource from your Strings.xml file you will use the syntax: android:text="@string/STRINGNAME". This tells the IDE you are pulling the string from your Strings.xml resource file and that you don't want the exact text you are inputting.
EDIT
Ok with the addition of your Layout XML you clarified a bunch :) I can see you generated a Blank activity which is configured using a Coordinator Layout. A secondary layout should have been auto-generated with that labeled content_main.xml. This is where you need to look for your TextView. You are looking at the main layout but not the container found within the unit.
Solution 2:
Although, the tutorial in the link has plenty of info, it is not well organized/structured.
In order to show a "Hello World!" text, you should paste this in the xml of your activity (MainActivity - maybe) :
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"/>
If you really want to use "Hello World!" as a string resource just add in strings.xml
<string name="text_4_my_hello_world_example">Hello World!</string>
And change in the code above the following
android:text="@string/text_4_my_hello_world_example"
Good luck and have fun learning!
Solution 3:
first of all the property name must be "hello_world
", don´t use capital characters, it will cause problems in your proyect!
<string name="hello_world">Darryl is learning Android!</string>
Then just add the reference:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world"/>
Then you will see the sentence Darryl is learning Android!
displayed in your TextView
.
The value <string name="hello_world">Darryl is learning Android!</string>
must be setted inside /res/values/strings.xml
To open the layout that contains the TextView
go to /res/layout/activity_main.xml or /res/layout/activity_my.xml like in your example.
Solution 4:
Because in your layout file, TextView's text attribute must be like this:
android:text="@string/hello_world"
If you create a new string in strings.xml:
<string name="my_string">My Beautiful String</string>
And call it in your TextView:
<TextView
...
android:text="@string/my_string"
... />
This should work.
Post a Comment for "How To Print Message In An Android App"