I'm pretty new to developing Android applications but I am attempting to display the score at the end of a game I am making.
I was planning on switching to a view using:
setContentView(R.layout.over);
And that seems to work but I want to display the score.
I defined a textView:
<TextView android:text="@+id/TextView02" android:id="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
But would like to change the text to read: "Score: (dynamic text from variable here)". Obviously I need to reference that variable somehow, or set the text of the textView before changing to this view.
Please help!
Android App Development for Beginners This example demonstrates how do I create multiple styles inside a TextView in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.
On your Android phone or tablet, install Gboard. Open any app that you can type with, like Gmail or Keep. Tap where you can enter text. Slide your finger across the letters to spell the word you want.
Text View: This class is used to display text on the android application screen. It also allows user to optionally edit it.
That should solve your problem:
TextView tv = (TextView)findViewById(R.id.TextView02);
tv.setText("Text to set");
Why do u assign to text and id the same values?
Greg's Answer's pretty much what you want, but customized to what you are looking for:
TextView tv = (TextView)findViewById(R.id.TextView02);
tv.setText("Score: "+scoreVariable);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With