2013-02-04 7 views
0

최대 this question까지 후속 작업으로, 사용자 지정 TextView (번역 목적으로 사용자 지정 글꼴이있는)를 사용하여 WheelView를 성공적으로 구현했습니다.사용자 지정 TextView가있는 WheelView는 currentItem을 강조 표시하지 않습니다.

adapter.setItemResource(R.layout.layout_item); 
adapter.setItemTextResource(R.id.text); 

이제 문제는 휠뷰가 현재 항목을 강조 표시하지 않는다는 것입니다.

어댑터 코드 : 위의 코드에서

/** 
* 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로 이동하지 않습니다.

Original source of WheelView.

답변

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); 
    } 
} 
관련 문제