Search code examples
xmlandroidtextviewsettext

TextView defined in main.xml - how to "name" it to be able to use - setText() method?


I am exploring android and developement and I found one problem.

My app UI is defined in main.xml

I have 2 texts and 2 buttons defined - easy app.

I read that I may be able to change TEXT in the ACTIVITY using the setText() method.

And thats the problem - how do I POINT the setText() Method? How do I tell it to change a specified text?

If I would declare the TextView inside the Activity with NEW TextView NAME Object, I would just need to use NAME.setText(STRING)... But I didnt so i dont have anything like NAME of the object?

How can this be done?


Solution

  • You don't need do define a new TextView. You need this code:

    TextView textView = (TextView) findViewById(R.id.name_of_your_textview);
    textView.setText("bla bla bla");