如何在屏幕上显示变量的值? [英] How to display the value of a variable on the screen?
问题描述
我知道这是一个非常基本的问题,但是我需要知道如何在屏幕上显示变量的内容.
I know this is very basic question, but I need to know, how I can display the contents of a variable on the screen.
我在布局中使用文本视图吗?
Do I use a textview in my layout?
我有一个textview框,可以在编辑器中将其设置为要说些什么,但我需要编写变量的内容,以便进行一些错误检查.
I have a textview box and I can set it to say something in the editor but I need to write the contents of a variable so I can do some error checking.
有人帮忙吗?
推荐答案
如果在布局XML文件中定义了一个名为textViewName的TextView,则可以在Activity类中执行以下操作:
If you have a TextView named textViewName defined in your layout XML file, you can just do something like this in your Activity class:
setContentView(R.layout.layoutName);
TextView textView = (TextView) findViewById(R.id.textViewName);
textView.setText("text you want to display");
这是您要找的吗?如果您不需要将其显示在屏幕上,而只想调试,则只需使用Log()和logcat来查看消息.
Is this what you're looking for? If you don't need to display it to the screen, and just want to debug, just use Log() and logcat to view the messages.
这篇关于如何在屏幕上显示变量的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!