Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display dynamic text in an Android view

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!

like image 964
sirmdawg Avatar asked Jul 25 '11 19:07

sirmdawg


People also ask

How can we display text in multiple styles in android?

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.

How do you slide text on android?

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.

Is a view in android which is capable of showing text?

Text View: This class is used to display text on the android application screen. It also allows user to optionally edit it.


2 Answers

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?

like image 132
gregory561 Avatar answered Sep 19 '22 11:09

gregory561


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);
like image 44
Robby Cohen Avatar answered Sep 21 '22 11:09

Robby Cohen