2013-02-04 110 views
0

作爲this question的後續操作,我已成功實現帶有自定義TextView(具有用於翻譯目的的自定義字體)的WheelView。現在帶有自定義TextView的WheelView不會突出顯示currentItem

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不惜一切來選擇項目。 WheelView的

Original source

回答

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