Android TextView text not updating at run time

I need to miss something completely stupid because updating a TextView should be an easy task. I have an Activity class that is an observer of another that receives messages. In my onCreate work, I do the following and it works great.

theStatus = (TextView) findViewById(R.id.theStatus);
theStatus.setText("waiting");

Later, when the message action receives a new message, it passes it to the observer (my activity)

public void statusUpdate( GenericMessage aMessage )
{
    String statusText = aMessage.getDetails();
    theStatus.setText(statusText);

    theSessionStatus.invalidate();  // I've tried with and without this call
}

However, the screen does not refresh. I have to miss something ...

+3
source share
1 answer

Looks like I found a solution, although it looks like a hack. I got this idea from your comments above and from here .

Handler Activity B , , . B Handler onCreate:

  Handler statusHandler = new Handler();
  statusHandler.post(new Runnable() 
  {
      public void run()
      {
         statusUpdate();
      }
  });

C ( B ) , B . C , :

theMsgObserverHandle.post(new Runnable()
{
   public void run()
   {
      Log.d(myName, "Calling my Observer statusUpdate");  

      theMsgObserver.statusUpdate();
   }
});

, , B . ( - not android.os.Message) B C (C - Singleton) . , , . - , .

0

Source: https://habr.com/ru/post/1763153/


All Articles