我这里有代码,我想在listview中更改字体并在listadapter中显示它。但是,它没有帮助,只显示默认数字而不是真实数据。这是更改我的数据字体的正确方法吗?
ListAdapter adapter = new SimpleAdapter(
AllProductsActivity3.this, productsList,
R.layout.list_item3, new String[] { TAG_PID,
TAG_NAME, TAG_PRICE, TAG_DESCRIPTION},
new int[] { R.id.pid, R.id.username,R.id.p_title, R.id.approval }){
@Override
public View getView(int pos, View convertView, ViewGroup parent){
View v = convertView;
if(v== null){
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v=vi.inflate(R.layout.list_item3, null);
}
TextView tv = (TextView)v.findViewById(R.id.username);
Typeface custom_fontG = Typeface.createFromAsset(getAssets(),
"fonts/orange juice 2.0.ttf");
tv.setTypeface(custom_fontG);
TextView tv2 = (TextView)v.findViewById(R.id.p_title);
Typeface custom_fontH = Typeface.createFromAsset(getAssets(),
"fonts/orange juice 2.0.ttf");
tv2.setTypeface(custom_fontH);
TextView tv3 = (TextView)v.findViewById(R.id.approval);
Typeface custom_fontI = Typeface.createFromAsset(getAssets(),
"fonts/orange juice 2.0.ttf");
tv3.setTypeface(custom_fontI);
return v;
}
答案 0 :(得分:2)
将文字设置为TextView
tv.setText(fetch data from arrayList as per Position);
tv.setText(""+pos);
对其他TextViews
答案 1 :(得分:0)
尝试这样可以帮到你,
ListAdapter adapter = new SimpleAdapter(
AllProductsActivity3.this, productsList,
R.layout.list_item3, new String[] { TAG_PID,
TAG_NAME, TAG_PRICE, TAG_DESCRIPTION},
new int[] { R.id.pid, R.id.username,R.id.p_title, R.id.approval }){
@Override
public View getView(int pos, View convertView, ViewGroup parent){
View v = convertView;
if(v== null){
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v=vi.inflate(R.layout.list_item3, null);
}
HashMap<String,String> value = productsList.get(pos);
TextView tv = (TextView)v.findViewById(R.id.username);
Typeface custom_fontG = Typeface.createFromAsset(getAssets(),
"fonts/orange juice 2.0.ttf");
tv.setTypeface(custom_fontG);
tv.setText(value.get(//put key to get value from hashmap));
TextView tv2 = (TextView)v.findViewById(R.id.p_title);
Typeface custom_fontH = Typeface.createFromAsset(getAssets(),
"fonts/orange juice 2.0.ttf");
tv2.setTypeface(custom_fontH);
tv2.setText(value.get(//put key to get value from hashmap));
TextView tv3 = (TextView)v.findViewById(R.id.approval);
Typeface custom_fontI = Typeface.createFromAsset(getAssets(),
"fonts/orange juice 2.0.ttf");
tv3.setTypeface(custom_fontI);
tv3.setText(value.get(//put key to get value from hashmap));
return v;
}
答案 2 :(得分:0)
重命名您的字体文件名
Typeface custom_fontG = Typeface.createFromAsset(getAssets(),
"fonts/orange juice 2.0.ttf");
到Typeface custom_fontG = Typeface.createFromAsset(getAssets(),
"fonts/orange_juice_2.0.ttf");
使用_
空间