-1

setText("hello") doesn't work

I have it in my onCreate

TextView tx = (TextView) findViewById(R.id.stuff);

tx.setText("hello");

It stays blank.

Rohit Arya
  • 6,751
  • 1
  • 26
  • 40
shake
  • 11
  • 2

1 Answers1

1

an old answer: Java Android SetText Doesnt Work

try:

tx.post(new Runnable() {
    @Override
    public void run() {
        tx.setText("hello");
    }
});

Sometimes the TextView hasn't finished being created, so your setText() won't apply yet. This makes sure it's done after it's finished creation.

Community
  • 1
  • 1
TWL
  • 6,228
  • 29
  • 65
  • sometimes it was just that extra five servings of ice cream, that made you a bit slower, anyways, don't relay on it, the `post` will wait for it. – TWL Aug 16 '16 at 05:53