0

この質問のフォローアップとして、WheelView をカスタム TextView (翻訳用のカスタム フォントを持つ) で正常に実装しました。

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 に答える