I receive data from udp server from my application.when i receive data i have to show that on the screen.I just use the Textview to display the incoming data(textview.setText("data")).But it displays the last incoming data only.I need to show the previous data also.how to solve this?
DatagramSocket clientsocket=new DatagramSocket(6363);
byte开发者_StackOverflow社区[] receivedata=new byte[1024];
while(true)
{
DatagramPacket recv_packet=new DatagramPacket(receivedata, receivedata.length);
textview.setText("UDP S: Receiving...");
clientsocket.receive(recv_packet);
String rec_str=new String(recv_packet.getData());
textview.setText(" Received String "+rec_str);
}
when i use append method it display's after all the incoming finished. I need to view when the data is coming at that time i have to show that.
You can try using the append
method from the TextView instead of setText
To append something at the end of current content
textview.setText( "Recieved String " + textview.getText() + rec_str);
try using
yourobject.invalidateViews();
to force an update
精彩评论