0

So I have a textview in which I tv.append some strings when my listener get's some specific data. The problem is, that textview updates the text only when I move to another view or hide app in the background and then get it back to the front. So basicaly i make a textview, Then I have a listener based on asmack library (XMPP) When i recieve a messgae I append it to textview, but i can see it only by moving to another view and going back.

    tv = (TextView)findViewById(R.id.textwindow);

chat = xmpp.getChatManager().createChat(contactid, new MessageListener() {
                public void processMessage(Chat chat, Message message) {                  
                   System.out.println("Reciveved:"+ message);
                 tv.append("From:"+chat.getParticipant()+"\n"+message.getBody()+"\n");

                }                                       
                    }
            );;
artouiros
  • 3,947
  • 12
  • 41
  • 54

1 Answers1

4

You can force a redraw by calling the invalidate() method on either the View or its containing ViewGroup. So in your code above, you could modify your processMessage() method like this:

public void processMessage(Chat chat, Message message) {                  
  System.out.println("Reciveved:"+ message);
  tv.append("From:"+chat.getParticipant()+"\n"+message.getBody()+"\n");
  tv.invalidate();         
}

You might want to take a look at a related question answered here.

Community
  • 1
  • 1
jengelsma
  • 8,192
  • 4
  • 21
  • 21