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

前端 未结 5 865
别那么骄傲
别那么骄傲 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:52

    In the Activity...

      public void onCreate(Bundle savedInstanceState)
      {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
        int myValue = deriveMyValue();
        String message =
            myValue == -1 ?
                "The value is invalid." :
                "The value is " + myValue;
        TextView tv = (TextView) findViewById(R.id.my_text_view);
        tv.setText(message);
      }

提交回复
热议问题