I am looking for a way to create a chat fragment. So basically I am trying to make a fragment dynamic. As a first step I am trying to update a textview which I have to display messages received. I am using XMPP as a client and I am receiving message through the following function:
@Override
public void processMessage(Chat arg0, org.jivesoftware.smack.packet.Message message) {
// TODO Auto-generated method stub
String from = message.getFrom();
String body = message.getBody();
System.out.println(String.format("Received message '%1$s' from %2$s", body, from));
text.setText(String.format("'%1$s' from %2$s", body, from));
}
Any help regarding dynamically updating a textview in a fragment is appreciated.
Thanks
Max
In the processMessage() function, you can do
getView().findViewById(id_of_text_view);
getView()
returns the View created inonCreateView()
http://developer.android.com/reference/android/app/Fragment.html#getView%28%29
Example of
MyFragment
that allow text update:Example of
Activity
that holds theMyFragment
: