Search code examples
androidtextviewsettext

TextView.setText does not always working?


I have 12 TextView on the screen, and If any of it is clicked then I change the text using TextView.setText().

It works fine most of time, but some times the new text just do not appear when I clicked some of the TextView. A empty TextView is displayed.

I thought it was my mistake to set a wrong text to the view, but then I found that when I switch to some other app or home screen and go back to my app, the right text shows up, it looks like I have already set the correct text but it is just not displayed correctly.

Do I need to call some functions like refresh() or something to make sure the text show up?

The code is something like this:

textViews[sn].setText(showingWords[sn].spell);

and this is called repeatedly with different sn. And I can assure the spell value is correct because I can see the correct value displayed if I change to another app and change back.


Solution

  • if refreshing activity is your problem..you can refresh your activity at anytime by inserting the below two lines of code after set text . But refreshing activity many number of times may not be good idea .

        finish();
        startActivity(getIntent());