2015-05-27 11 views
0

格式文本我有這樣的代碼:ANDROID:ArrayList中

public static HashMap<String, List<String>> getInfo() 

{ 

HashMap<String, List<String>> Conteudo = new HashMap<String, List<String>>(); 

List<String> Areas_Processos = new ArrayList<>(); 

Areas_Processos.add("<>start of bold directive<>"+"4 - text four"+"end of bold directive<>"); 

... 

} 

輸出是<>start of bold directive<>4 - Text four <>end of bold directive<>,顯示指示格式化文本。

我的期望是有粗體格式的文本,就像這樣: 「4 - 參考譯文:

任何想法?

+2

@MD你爲什麼不做呢? –

回答

0

它看起來像你試圖使用大膽 html標籤,我還沒有見過<>start of bold directive<>之前。如果你能/要使用<b></b>標籤,那麼你可以使用Android的Html.fromHtmlmethod

textView.setText(Html.fromHtml("<b>This will be bold.</b> This will not")); 
0

你怎麼樣存儲Spannable到您ArrayList代替

HashMap<String, List<Spannable>> Conteudo = new HashMap<String, List<Spannable>>(); 

List<Spannable> Areas_Processos = new ArrayList<Spannable>(); 

爲了使字符串大膽或部分,你可以有如下:

String str = "4 - text four"; 
Spannable sb = new SpannableString(str); 
sb.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, str.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 

商店他們進入你的ArrayList然後進入HashMap像:

Areas_Processos.add(sb); 
Conteudo.put("mykey", Areas_Processos); 

如何使用SpannableTextView

TextView v = (TextView) findViewById(R.id.txtVwSomething); 
HashMap<String, List<Spannable>> Conteudo = getInfo(); 
List<Spannable> sp = Conteudo.get("mykey"); 
v.setText(sp.get(i)); // i = index of your Spannable in ArrayList 

你可以不只是大膽提供一些其他格式。你可以得到幫助here