简体   繁体   English

在Android视图中显示动态文本

[英]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. 我是开发Android应用程序的新手,但我试图在我正在制作的游戏结束时显示分数。

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:

<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. 显然我需要以某种方式引用该变量,或者在更改为此视图之前设置textView的文本。

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? 为什么你要分配文本和id相同的值?

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. 我应该使用一个对话框窗口来显示Scrore。 here ypou have how to create differents dialogs. 在这里,你有如何创建不同的对话框。

http://developer.android.com/guide/topics/ui/dialogs.html http://developer.android.com/guide/topics/ui/dialogs.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM