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");

                }                                       
                    }
            );;
2
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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.