Azuken Posted October 19, 2012 Share Posted October 19, 2012 Bonjour, Je débute tout juste dans le développement d'applications android, et je désire faire une appli toute simple, qui lorsque l'on clique sur un bouton, cela met un texte aléatoire dans un TextView. Seulement il me génère une erreur : the specified child already has a parent. you must call removeview() on the child's parent first. Et je ne vois pas ce que cela veut exactement dire. final TextView changedText = (TextView)findViewById(R.id.changedText); final Button aleaButton = (Button)findViewById(R.id.aleaButton); aleaButton.setonclickListener(new View.onclickListener() { public void onclick(View v) { Random r = new Random(); int numText = r.nextInt(4); switch (numText) { case 0: changedText.setText("Bienvenue chez Osys."); break; case 1: changedText.setText("Développement Android"); break; case 2: changedText.setText("Quartis Optima"); break; case 3: changedText.setText("Ecran Dell"); break; case 4: changedText.setText("Téléphone Alcatel"); break; default: break; } setContentView(changedText); } }); Pourriez vous m'aider ? Merci d'avance, Azuken Link to comment Share on other sites More sharing options...
chpil Posted October 19, 2012 Share Posted October 19, 2012 Inutile de faire le setContentView dans ta méthode onclick (sinon tu lui dis de remplacer la vue de ton Activity par ce TextView, qui est lui même déjà contenu dans un layout, d'où l'erreur...) Link to comment Share on other sites More sharing options...
Azuken Posted October 19, 2012 Author Share Posted October 19, 2012 Oui, j'ai vu ça, et maintenant ça fonctionne ! :) Merci ! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.