作为this question的后续,我已成功使用自定义TextView(其具有用于翻译目的的自定义字体)实现了WheelView。
adapter.setItemResource(R.layout.layout_item);
adapter.setItemTextResource(R.id.text);
现在的问题是,wheelview并没有突出显示当前的项目。
适配器代码:
/**
* Adapter for string based wheel. Highlights the current value.
*/
private class DateArrayAdapter extends ArrayWheelAdapter<String> {
// Index of current item
int currentItem;
// Index of item to be highlighted
int currentValue;
/**
* Constructor
*/
public DateArrayAdapter(Context context, String[] items, int current) {
super(context, items);
this.currentValue = current;
setTextSize(16);
}
@Override
protected void configureTextView(TextView view) {
super.configureTextView(view);
if (currentItem == currentValue) {
view.setTextColor(getResources().getColor(R.color.holo_blue));
}
view.setTypeface(Typeface.SANS_SERIF);
view.setTextSize(18);
}
@Override
public View getItem(int index, View cachedView, ViewGroup parent) {
currentItem = index;
return super.getItem(index, cachedView, parent);
}
}
在上面的代码中,它根本不会转到configureTextView
来突出显示该项目。
答案 0 :(得分:0)
好的,我明白了。万一它可以帮助其他人,这里是代码:
/**
* Adapter for string based wheel. Highlights the current value.
*/
private class DateArrayAdapter extends ArrayWheelAdapter<String> {
// Index of current item
int currentItem;
// Index of item to be highlighted
int currentValue;
/**
* Constructor
*/
public DateArrayAdapter(Context context, String[] items, int current) {
super(context, items);
this.currentValue = current;
setItemResource(R.layout.wheelview_textview);
setItemTextResource(R.id.wheelview_date);
setTextSize(16);
}
protected void configureTextView(CustomTextView view) {
super.configureTextView(view);
if (currentItem == currentValue) {
view.setTextColor(getResources().getColor(R.color.holo_blue));
}
}
@Override
public View getItem(int index, View cachedView, ViewGroup parent) {
currentItem = index;
View view = super.getItem(index, cachedView, parent);
CustomTextView date = (CustomTextView) view.findViewById(R.id.wheelview_date);
configureTextView(date);
return view;
//return super.getItem(index, cachedView, parent);
}
}