我正在寻找一种方法来创建聊天片段。所以基本上我试图使一个片段动态。作为第一步,我试图更新一个textview,我必须显示收到的消息。我使用XMPP作为客户端,我通过下面的函数接收消息:动态更改片段中的TextView(公共void processMessage)
@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));
}
任何帮助关于动态地更新在一个片段一个TextView理解。的MyFragment
由于
最大
创建的视图如何实际上你跟片段工作? – andrew 2013-05-03 15:47:04
嗯,我不知道你想知道什么,但我使用onCreateView来设置我的用户界面,除此之外,没有使用其他功能。 – Max 2013-05-03 15:54:56
我的意思是说你没有显示与片段一起工作的代码。好的,你可以在你的fragment中创建一个方法,比如:'updateText(String text)',它将与'TextView'交互,你可以通过在你的fragment中使用'findViewById'来检索。在你的活动中,你可以使用'myFragment =(MyFragment)getFragmentManager()。findFragmentById(id)'来找到你的片段。然后,只需调用此方法,例如:'myFragment.updateText(“new message”);' – andrew 2013-05-03 16:07:15