开发者

How to update the screen in Android?

I have to show the received data of a UDP server. When data is coming from the server at that time I have to show that on the screen one by one. How to update the screen (Textview (or) EditText)?

I need to add (rec_str) value to the screen.

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) {
        开发者_JAVA技巧Log.e("UDP", "S: Error", e);
    }
}

When I use settext it displays the last text only. How can I see all the incomming data? (Data will come one by one. When the data is comming I need to display the current data with the existing data also.)


You should set your TextView using setText(CharSequence text) method, passing your rec_str String.

Take a look to the class reference, there are several different setText() methods accepting different kind of input:

http://developer.android.com/reference/android/widget/TextView.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜