androidtextviewruntimesettext

Setting text in a TextView at runtime


I'm a newbie to Android Development so I'm probably drowning in an inch of water...
I have a layout.xml file with a TextView and some buttons, set where i need them. Is there a way to change just the text displayed without having to recreate the entire layout programmatically? Thanks for you patience :D


Solution

  • After defining your TextView in onCreate(), just call setText(string) property.

    Edited:

    setContentView(R.layout.your_current_layout);
    TextView mytextview = (TextView) findViewById(R.id.textView1);
    mytextview.setText("I'm called from your activity");
    

    Enjoy :-)