无法容纳我的微调器。好吧,我正在用它从strings.xml中填充一个字符串数组,但现在我想向该数组添加自定义字体。我第一次使用Custom ArrayAdapter,它正在覆盖其布局xml中的“ android:entries =“和” android:prompt =“。
因此,我需要使用strings.xml中的数组填充此微调器
(在onCreate内)
spinner1 = (Spinner) findViewById(R.id.distancespinner);
MyArrayAdapter ma = new MyArrayAdapter(this, R.layout.my_spinner_style);
spinner1.setAdapter(ma);
然后:
private class MyArrayAdapter extends ArrayAdapter {
Typeface font = Typeface.createFromAsset(getAssets(), "fonts/m01.TTF");
public MyArrayAdapter(Context context, int textViewResourceId) {
super(context, textViewResourceId);
}
public TextView getView(int position, View convertView, ViewGroup parent) {
TextView v = (TextView) super.getView(position, convertView, parent);
v.setTypeface(font);
return v;
}
public TextView getDropDownView(int position, View convertView, ViewGroup parent) {
TextView v = (TextView) super.getView(position, convertView, parent);
v.setTypeface(font);
return v;
}
}
我尝试添加条目并在my_spinner_style.xml内再次提示...
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/spinnerTarget"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:entries="@array/location_arrays"
android:prompt="@string/location_prompt"
android:singleLine="True" />
但是,这也不起作用。
那是我重写的代码,并且运行良好:
Spinner spinner = (Spinner) findViewById(R.id.distancespinner);
spinner.setPromptId(R.string.location_prompt);
MyArrayAdapter ma = new MyArrayAdapter(this, R.layout.my_spinner_style);
ma.addAll(Arrays.asList(getResources().getStringArray(
R.array.location_arrays)));
spinner.setAdapter(ma);
和XML
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/spinnerTarget"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="True" />
Adapter
是一样的
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句