android.widget.SpinnerAdapter#getView ( )源码实例Demo

下面列出了android.widget.SpinnerAdapter#getView ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: revolution-irc   文件: AutoResizeSpinner.java
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    SpinnerAdapter adapter = getAdapter();
    if (adapter != null && MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.AT_MOST) {
        View view = adapter.getView(getSelectedItemPosition(), null, this);
        if (view.getLayoutParams() == null)
            view.setLayoutParams(mDefaultLayoutParams);
        view.measure(widthMeasureSpec, heightMeasureSpec);
        int width = view.getMeasuredWidth();
        if (getBackground() != null) {
            getBackground().getPadding(mTempRect);
            width += mTempRect.left + mTempRect.right;
        }

        this.setMeasuredDimension(Math.min(width, MeasureSpec.getSize(widthMeasureSpec)), this.getMeasuredHeight());
    }

}
 
源代码2 项目: MDPreference   文件: Spinner.java
private int measureContentWidth(SpinnerAdapter adapter, Drawable background) {
if (adapter == null)
          return 0;	        

      int width = 0;
      View itemView = null;
      int itemType = 0;
      
      final int widthMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
      final int heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);

      // Make sure the number of items we'll measure is capped. If it's a huge data set
      // with wildly varying sizes, oh well.
      int start = Math.max(0, getSelectedItemPosition());
      final int end = Math.min(adapter.getCount(), start + MAX_ITEMS_MEASURED);
      final int count = end - start;
      start = Math.max(0, start - (MAX_ITEMS_MEASURED - count));
      for (int i = start; i < end; i++) {
          final int positionType = adapter.getItemViewType(i);
          if (positionType != itemType) {
              itemType = positionType;
              itemView = null;
          }
          itemView = adapter.getView(i, itemView, null);
          if (itemView.getLayoutParams() == null)
              itemView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
          
          itemView.measure(widthMeasureSpec, heightMeasureSpec);
          width = Math.max(width, itemView.getMeasuredWidth());
      }

      // Add background padding to measured width
      if (background != null) {
          background.getPadding(mTempRect);
          width += mTempRect.left + mTempRect.right;
      }

      return width;
  }
 
源代码3 项目: attendee-checkin   文件: FlexSpinner.java
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    int selectedPosition = getSelectedItemPosition();
    SpinnerAdapter adapter = getAdapter();
    if (selectedPosition >= 0 && adapter != null && selectedPosition < adapter.getCount()) {
        View view = adapter.getView(selectedPosition, null, this);
        measureChild(view, widthMeasureSpec, heightMeasureSpec);
        float padding = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, ARROW_PADDING,
                getResources().getDisplayMetrics());
        setMeasuredDimension(Math.min((int) (view.getMeasuredWidth() + padding),
                MeasureSpec.getSize(widthMeasureSpec)), getMeasuredHeight());
    }
}
 
源代码4 项目: material   文件: Spinner.java
private int measureContentWidth(SpinnerAdapter adapter, Drawable background) {
if (adapter == null)
          return 0;	        

      int width = 0;
      View itemView = null;
      int itemType = 0;
      
      final int widthMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
      final int heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);

      // Make sure the number of items we'll measure is capped. If it's a huge data set
      // with wildly varying sizes, oh well.
      int start = Math.max(0, getSelectedItemPosition());
      final int end = Math.min(adapter.getCount(), start + MAX_ITEMS_MEASURED);
      final int count = end - start;
      start = Math.max(0, start - (MAX_ITEMS_MEASURED - count));
      for (int i = start; i < end; i++) {
          final int positionType = adapter.getItemViewType(i);
          if (positionType != itemType) {
              itemType = positionType;
              itemView = null;
          }
          itemView = adapter.getView(i, itemView, this);
          if (itemView.getLayoutParams() == null)
              itemView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
          
          itemView.measure(widthMeasureSpec, heightMeasureSpec);
          width = Math.max(width, itemView.getMeasuredWidth());
      }

      // Add background padding to measured width
      if (background != null) {
          background.getPadding(mTempRect);
          width += mTempRect.left + mTempRect.right;
      }

      return width;
  }
 
源代码5 项目: CSipSimple   文件: IcsSpinner.java
int measureContentWidth(SpinnerAdapter adapter, Drawable background) {
    if (adapter == null) {
        return 0;
    }

    int width = 0;
    View itemView = null;
    int itemType = 0;
    final int widthMeasureSpec =
        MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
    final int heightMeasureSpec =
        MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);

    // Make sure the number of items we'll measure is capped. If it's a huge data set
    // with wildly varying sizes, oh well.
    int start = Math.max(0, getSelectedItemPosition());
    final int end = Math.min(adapter.getCount(), start + MAX_ITEMS_MEASURED);
    final int count = end - start;
    start = Math.max(0, start - (MAX_ITEMS_MEASURED - count));
    for (int i = start; i < end; i++) {
        final int positionType = adapter.getItemViewType(i);
        if (positionType != itemType) {
            itemType = positionType;
            itemView = null;
        }
        itemView = adapter.getView(i, itemView, this);
        if (itemView.getLayoutParams() == null) {
            itemView.setLayoutParams(new ViewGroup.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT));
        }
        itemView.measure(widthMeasureSpec, heightMeasureSpec);
        width = Math.max(width, itemView.getMeasuredWidth());
    }

    // Add background padding to measured width
    if (background != null) {
        background.getPadding(mTempRect);
        width += mTempRect.left + mTempRect.right;
    }

    return width;
}
 
源代码6 项目: android-apps   文件: IcsSpinner.java
int measureContentWidth(SpinnerAdapter adapter, Drawable background) {
    if (adapter == null) {
        return 0;
    }

    int width = 0;
    View itemView = null;
    int itemType = 0;
    final int widthMeasureSpec =
        MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
    final int heightMeasureSpec =
        MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);

    // Make sure the number of items we'll measure is capped. If it's a huge data set
    // with wildly varying sizes, oh well.
    int start = Math.max(0, getSelectedItemPosition());
    final int end = Math.min(adapter.getCount(), start + MAX_ITEMS_MEASURED);
    final int count = end - start;
    start = Math.max(0, start - (MAX_ITEMS_MEASURED - count));
    for (int i = start; i < end; i++) {
        final int positionType = adapter.getItemViewType(i);
        if (positionType != itemType) {
            itemType = positionType;
            itemView = null;
        }
        itemView = adapter.getView(i, itemView, this);
        if (itemView.getLayoutParams() == null) {
            itemView.setLayoutParams(new ViewGroup.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT));
        }
        itemView.measure(widthMeasureSpec, heightMeasureSpec);
        width = Math.max(width, itemView.getMeasuredWidth());
    }

    // Add background padding to measured width
    if (background != null) {
        background.getPadding(mTempRect);
        width += mTempRect.left + mTempRect.right;
    }

    return width;
}
 
源代码7 项目: zen4android   文件: IcsSpinner.java
int measureContentWidth(SpinnerAdapter adapter, Drawable background) {
    if (adapter == null) {
        return 0;
    }

    int width = 0;
    View itemView = null;
    int itemType = 0;
    final int widthMeasureSpec =
        MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
    final int heightMeasureSpec =
        MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);

    // Make sure the number of items we'll measure is capped. If it's a huge data set
    // with wildly varying sizes, oh well.
    int start = Math.max(0, getSelectedItemPosition());
    final int end = Math.min(adapter.getCount(), start + MAX_ITEMS_MEASURED);
    final int count = end - start;
    start = Math.max(0, start - (MAX_ITEMS_MEASURED - count));
    for (int i = start; i < end; i++) {
        final int positionType = adapter.getItemViewType(i);
        if (positionType != itemType) {
            itemType = positionType;
            itemView = null;
        }
        itemView = adapter.getView(i, itemView, this);
        if (itemView.getLayoutParams() == null) {
            itemView.setLayoutParams(new ViewGroup.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT));
        }
        itemView.measure(widthMeasureSpec, heightMeasureSpec);
        width = Math.max(width, itemView.getMeasuredWidth());
    }

    // Add background padding to measured width
    if (background != null) {
        background.getPadding(mTempRect);
        width += mTempRect.left + mTempRect.right;
    }

    return width;
}
 
源代码8 项目: zhangshangwuda   文件: IcsSpinner.java
int measureContentWidth(SpinnerAdapter adapter, Drawable background) {
    if (adapter == null) {
        return 0;
    }

    int width = 0;
    View itemView = null;
    int itemType = 0;
    final int widthMeasureSpec =
        MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
    final int heightMeasureSpec =
        MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);

    // Make sure the number of items we'll measure is capped. If it's a huge data set
    // with wildly varying sizes, oh well.
    int start = Math.max(0, getSelectedItemPosition());
    final int end = Math.min(adapter.getCount(), start + MAX_ITEMS_MEASURED);
    final int count = end - start;
    start = Math.max(0, start - (MAX_ITEMS_MEASURED - count));
    for (int i = start; i < end; i++) {
        final int positionType = adapter.getItemViewType(i);
        if (positionType != itemType) {
            itemType = positionType;
            itemView = null;
        }
        itemView = adapter.getView(i, itemView, this);
        if (itemView.getLayoutParams() == null) {
            itemView.setLayoutParams(new ViewGroup.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT));
        }
        itemView.measure(widthMeasureSpec, heightMeasureSpec);
        width = Math.max(width, itemView.getMeasuredWidth());
    }

    // Add background padding to measured width
    if (background != null) {
        background.getPadding(mTempRect);
        width += mTempRect.left + mTempRect.right;
    }

    return width;
}
 
int measureContentWidth(SpinnerAdapter adapter, Drawable background) {
    if (adapter == null) {
        return 0;
    }

    int width = 0;
    View itemView = null;
    int itemType = 0;
    final int widthMeasureSpec =
        MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
    final int heightMeasureSpec =
        MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);

    // Make sure the number of items we'll measure is capped. If it's a huge data set
    // with wildly varying sizes, oh well.
    int start = Math.max(0, getSelectedItemPosition());
    final int end = Math.min(adapter.getCount(), start + MAX_ITEMS_MEASURED);
    final int count = end - start;
    start = Math.max(0, start - (MAX_ITEMS_MEASURED - count));
    for (int i = start; i < end; i++) {
        final int positionType = adapter.getItemViewType(i);
        if (positionType != itemType) {
            itemType = positionType;
            itemView = null;
        }
        itemView = adapter.getView(i, itemView, this);
        if (itemView.getLayoutParams() == null) {
            itemView.setLayoutParams(new ViewGroup.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT));
        }
        itemView.measure(widthMeasureSpec, heightMeasureSpec);
        width = Math.max(width, itemView.getMeasuredWidth());
    }

    // Add background padding to measured width
    if (background != null) {
        background.getPadding(mTempRect);
        width += mTempRect.left + mTempRect.right;
    }

    return width;
}