我想为String的片段设置不同的字体。
该程序有效,但它没有格式化String
请帮忙
这是我的代码:
...
// List view
private ListView lista;
// Listview Adapter
ArrayAdapter<String> adapter;
// Search EditText
EditText poleSearch;
// ArrayList for Listview
ArrayList<HashMap<String, String>> productList;
...
List<String> customers = new ArrayList<String>();
if(myCursor.getCount()!=0){
myCursor.moveToFirst();
do{
String myStringCode = "<big> "+myCursor.getString(0)+" </big> \n <small> Adres: "+myCursor.getString(1)+" </small>";
Spanned spanned = Html.fromHtml(myStringCode);
customers.add( spanned.toString());
}while(myCursor.moveToNext());
}
}
...
adapter = new ArrayAdapter<String>(this, R.layout.row_client, R.id.tvRC2, customers);
lista.setAdapter(adapter);
...
答案 0 :(得分:0)
使用Html格式化String时,需要使用break
标记插入换行符。所以用/n
<br></br>
String myStringCode = "<big> "+myCursor.getString(0)+" </big> <br></br> <small> Adres: "+myCursor.getString(1)+" </small>";
答案 1 :(得分:0)
您还可以使用SpannableString并为字符串的不同部分设置不同字体的范围
TypefaceSpan ts=new TypefaceSpan("<your font>");
SpannableString s=new SpannableString("");
s.setSpan(ts, 0, 3, 0);