0

作为对这个问题的跟进,我已经成功实现了带有自定义 TextView 的 WheelView(它具有用于翻译目的的自定义字体)。

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突出显示该项目。

WheelView 的原始来源

4

1 回答 1

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);
    }
}
于 2013-02-04T20:24:30.533 回答