How to display the value of a variable on the screen?

前端 未结 5 872
别那么骄傲
别那么骄傲 2021-01-03 23:20

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?

I have

5条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-03 23:37

    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");
    

    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.

提交回复
热议问题