问题
I am using Yuri Kanivets' WheelView in my project.
For translation purposes, I have made a custom TextView with custom Font. The WheelView uses TextView to display text. I would like to use the custom Textview in Wheelview so that it displays the text in custom font. How do I do that?
I don't want to change the original source of wheelview, in case I have to use it for other apps.
Code of the wheelview adapter:
/**
* 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);
}
}
回答1:
Create a layout xml with your own view. Let us say it is layout_item.xml
. Set the id of your view (the custom textview) to text using android:id="@+id/text"
Use this on your adapter:
adapter.setItemResource(R.layout.layout_item);
adapter.setItemTextResource(R.id.text);
I guess now it should work
来源:https://stackoverflow.com/questions/14690393/change-textview-of-wheelview