fredm72 Posted March 2, 2010 Share Posted March 2, 2010 Bonsoir à tous, Je continu mon apprentissage d'android et cette fois ci j'ai un problème de formatage de TextView. J'ai 2 Textview dans un LinearLayout. Pour essayer l'interface Spannable Je voudrais avoir le premier TextView en bleu souligné et le second en rouge. Le code ressemble à ça (c'est un extrait de mon code): TextView t1, t2; Spannable sText, sText2; t1= (TextView)this.findViewById(R.id.on); t2= (TextView)this.findViewById(R.id.kun); ..... t1.setText(on, TextView.BufferType.SPANNABLE); Spannable sText = (Spannable) on.getText(); sText.setSpan(new ForegroundColorSpan(Color.BLUE), 0, on.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); sText.setSpan(new UnderlineSpan(), 0, on.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); ....... t2.setText(kun, TextView.BufferType.SPANNABLE); Spannable sText2 = (Spannable) on.getText(); sText2.setSpan(new ForegroundColorSpan(Color.RED), 0, kun.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); sText2.setSpan(new UnderlineSpan(), 0, kun.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); Le premier (t1) est correctement formater, quand au second rien ne change. J'ai beau tourné le problème dans tout les sens rien n'y fait J'ai mis en commentaire le formatage du premier TextView, au cas ou, pas de résultat non plus. Dans mon xml, j'ai positionner android:bufferType="spannable" Quelqu'un aurait il déjà eu le même soucis? merci d'avance, Quote Link to comment Share on other sites More sharing options...
Caballero Posted March 2, 2010 Share Posted March 2, 2010 Spannable sText2 = (Spannable) kun.getText(); ce serait pas ça le soucis ? Quote Link to comment Share on other sites More sharing options...
fredm72 Posted March 2, 2010 Author Share Posted March 2, 2010 merci, mais malheureusement non. Il s'agit d'une erreur de copier coller. Dans mon code j'ai bien kun.getText(). Quote Link to comment Share on other sites More sharing options...
fredm72 Posted March 2, 2010 Author Share Posted March 2, 2010 Quelle nouille!!!! J'ai trouvé mon erreur. J'avais un kun.setText plus bas dans mon code mea culpa, comme on dit. Désolé pour le post inutile. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.