2010-06-25 100 views
0

我必須顯示UDP服務器的接收數據。當時數據來自服務器時,我必須逐個顯示在屏幕上。如何更新屏幕(Textview(或)EditText)?如何更新Android中的屏幕?

我需要將(rec_str)值添加到屏幕。

public void run() { 
    try { 
     DatagramSocket clientsocket = new DatagramSocket(9876); 
     byte[] receivedata = new byte[1024]; 
     while(true) 
     { 
      DatagramPacket recv_packet = new DatagramPacket(receivedata, receivedata.length); 
      Log.d("UDP", "S: Receiving..."); 
      clientsocket.receive(recv_packet); 
      String rec_str = new String(recv_packet.getData()); 
      Log.d(" Received String ",rec_str); 
      InetAddress ipaddress = recv_packet.getAddress(); 
      int port=recv_packet.getPort(); 
      Log.d("IPAddress : ",ipaddress.toString()); 
      Log.d(" Port : " ,Integer.toString(port)); 
     } 
    } catch (Exception e) { 
     Log.e("UDP", "S: Error", e); 
    } 
} 

當我使用settext它只顯示最後一個文本。我怎樣才能看到所有的數據? (數據將一一道來。當數據被我正在添加需要與現有的數據也顯示當前的數據。)

+0

份額的代碼的某些部分,請 – Cristian 2010-06-25 13:15:27

回答