我想为我的微调器应用自定义字体。我发现的唯一方法是创建一个自定义适配器。这是我的代码
private class CustomAdapter extends ArrayAdapter {
private Context context;
private List<CharSequence> itemList;
public CustomAdapter(Context context, int textViewResourceId,List<CharSequence> itemList) {
super(context, textViewResourceId);
this.context=context;
this.itemList=itemList;
}
public TextView getView(int position, View convertView, ViewGroup parent) {
TextView v = (TextView) super
.getView(position, convertView, parent);
Typeface myTypeFace = Typeface.createFromAsset(context.getAssets(),
"fonts/gilsanslight.otf");
v.setTypeface(myTypeFace);
v.setText(itemList.get(position));
return v;
}
public TextView getDropDownView(int position, View convertView,
ViewGroup parent) {
TextView v = (TextView) super
.getView(position, convertView, parent);
Typeface myTypeFace = Typeface.createFromAsset(context.getAssets(),
"fonts/gilsanslight.otf");
v.setTypeface(myTypeFace);
v.setText(itemList.get(position));
return v;
}
}
然后我用
List<CharSequence> itemList = new ArrayList<CharSequence>(
Arrays.asList(items));
mySpinnerArrayAdapter = new CustomAdapter(context,android.R.layout.simple_spinner_item,itemList);
spinner.setAdapter(mySpinnerArrayAdapter);
这样做之后,我的适配器是空的。谁能帮帮我吗 ?这些项目包含国家/地区列表。
亲切的问候,