I would like to print text by default in a textview before I wait for a socket connection. When a connection is established I would like to receive messages from the client and print them to the screen.
Hence I would like to first have one message printed and change this dynamiclly as time goes. The problem is that nothing is written to the screen until Oncreate() has ended. Please help me! Code: ------------- package com.example.ComEx; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.Socket; import java.net.UnknownHostException; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class ComEx extends Activity { /** Called when the activity is first created. */ private TextView t; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Socket kkSocket=null; PrintWriter out; BufferedReader in; t = (TextView) findViewById(R.id.textTest); printIt("Test the client layout"); try { kkSocket = new Socket("10.0.2.2", 5000); } catch (UnknownHostException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { out = new PrintWriter(kkSocket.getOutputStream(), true); in = new BufferedReader(new InputStreamReader( kkSocket.getInputStream())); out.println("Hej Oskar"); String fromServer; while ((fromServer = in.readLine()) != null) { printIt("Server "+fromServer); if (fromServer.equals("Bye.")) break; } }catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } private void printIt(String s){ t.setText(new StringBuffer(s)); } } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~----------~----~----~----~------~----~------~--~---