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: "Sc开发者_开发知识库ore: (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!
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);
I should use a dialog windows to show the Scrore. here ypou have how to create differents dialogs.
http://developer.android.com/guide/topics/ui/dialogs.html
精彩评论