gpt4 book ai didi

android - 自定义微调器适配器

转载 作者:IT老高 更新时间:2023-10-28 21:40:31 26 4
gpt4 key购买 nike

我想为我的微调器应用自定义字体。我发现的唯一方法是创建一个自定义适配器。这是我的代码

    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);

这样做之后,我的适配器是空的。谁能帮帮我吗 ?这些项目包含国家/地区列表。

亲切的问候,

最佳答案

试试

public View getView(int position, View convertView, ViewGroup parent) {

LayoutInflater inflater = getLayoutInflater();
View row = inflater.inflate(yourRowlayout, parent,
false);
TextView make = (TextView) row.findViewById(R.id.Make);
Typeface myTypeFace = Typeface.createFromAsset(context.getAssets(),
"fonts/gilsanslight.otf");
v.setTypeface(myTypeFace);
v.setText(itemList.get(position));
return row;
}


public View getDropDownView(int position, View convertView, ViewGroup parent) {

LayoutInflater inflater = getLayoutInflater();
View row = inflater.inflate(yourRowlayout, parent,
false);
TextView make = (TextView) row.findViewById(R.id.Make);
Typeface myTypeFace = Typeface.createFromAsset(context.getAssets(),
"fonts/gilsanslight.otf");
v.setTypeface(myTypeFace);
v.setText(itemList.get(position));
return row;
}

关于android - 自定义微调器适配器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12599703/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com