Comment ajouter un TextView dans un LinearLayout aprer 2sec
Bonjour à tous,
Voila je n'avez pas assez de place pour mieux expliciter mon problème dans le sujet...
J'ai créer un petit programme qui crée en xml un LinearLayout auquel j'ajoute au fil du temps des notification (ex: "Bienvenu","connexion ok","erreur",...)
Tout cela marche très bien jusqu'à se que je mette en place une ServerSocket :
En effet si je notifie "Connexion Ok" aprer le
Code:
Socket clientSocket = serverSocket.accept();
Mon programme plante et éclipse me parle de :
Exeption ViewRoot$CalledFromWrongThreadExeption
J'ai exactement le même problème lorsque je remplace l'accept() par :
Mon programme :
Class principale
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
public class Sbc extends Activity {
LinearLayout Notification_list;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Notification_list = (LinearLayout) findViewById(R.id.Notification_list);
notif("coucou");// MARCHE !
}
public void notif(String txt) {
TextView notif = new TextView(Notification_list);
notif.setText(txt);
Notification_list.addView(notif);
}
} |
Thread Serveur
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
public class Serveur extends Thread {
LinearLayout Notification_list;
Serveur(LinearLayout l) {
Notification_list = l;
notif("Wooo sa marche"); //MARCHE
sleep(2500);
notif(" :-( "); // Sa Plante !
}
public void notif(String txt) {
TextView notif = new TextView(Notification_list);
notif.setText(txt);
Notification_list.addView(notif);
}
} |
Toutes les idée son bonne à prendre.
Par avance merci !
;)