Example #1
0
		private int measureContentWidth(android.widget.ListAdapter adapter)
		{
			// Menus don't tend to be long, so this is more sane than it looks.
			int width = 0;
			android.view.View itemView = null;
			int itemType = 0;
			int widthMeasureSpec = android.view.View.MeasureSpec.makeMeasureSpec(0, android.view.View
				.MeasureSpec.UNSPECIFIED);
			int heightMeasureSpec = android.view.View.MeasureSpec.makeMeasureSpec(0, android.view.View
				.MeasureSpec.UNSPECIFIED);
			int count = adapter.getCount();
			{
				for (int i = 0; i < count; i++)
				{
					int positionType = adapter.getItemViewType(i);
					if (positionType != itemType)
					{
						itemType = positionType;
						itemView = null;
					}
					if (mMeasureParent == null)
					{
						mMeasureParent = new android.widget.FrameLayout(mContext);
					}
					itemView = adapter.getView(i, itemView, mMeasureParent);
					itemView.measure(widthMeasureSpec, heightMeasureSpec);
					width = System.Math.Max(width, itemView.getMeasuredWidth());
				}
			}
			return width;
		}
Example #2
0
		internal virtual int measureContentWidth(android.widget.SpinnerAdapter adapter, android.graphics.drawable.Drawable
			 background)
		{
			if (adapter == null)
			{
				return 0;
			}
			int width = 0;
			android.view.View itemView = null;
			int itemType = 0;
			int widthMeasureSpec = android.view.View.MeasureSpec.makeMeasureSpec(0, android.view.View
				.MeasureSpec.UNSPECIFIED);
			int heightMeasureSpec = android.view.View.MeasureSpec.makeMeasureSpec(0, android.view.View
				.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 = System.Math.Max(0, getSelectedItemPosition());
			int end = System.Math.Min(adapter.getCount(), start + MAX_ITEMS_MEASURED);
			int count = end - start;
			start = System.Math.Max(0, start - (MAX_ITEMS_MEASURED - count));
			{
				for (int i = start; i < end; i++)
				{
					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 android.view.ViewGroup.LayoutParams(android.view.ViewGroup
							.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
					}
					itemView.measure(widthMeasureSpec, heightMeasureSpec);
					width = System.Math.Max(width, itemView.getMeasuredWidth());
				}
			}
			// Add background padding to measured width
			if (background != null)
			{
				background.getPadding(mTempRect);
				width += mTempRect.left + mTempRect.right;
			}
			return width;
		}
Example #3
0
		public override void setAdapter(android.widget.ListAdapter adapter)
		{
			if (mAdapter != null && mDataSetObserver != null)
			{
				mAdapter.unregisterDataSetObserver(mDataSetObserver);
			}
			resetList();
			mRecycler.clear();
			mAdapter = adapter;
			mOldSelectedPosition = android.widget.AdapterView.INVALID_POSITION;
			mOldSelectedRowId = android.widget.AdapterView.INVALID_ROW_ID;
			// AbsListView#setAdapter will update choice mode states.
			base.setAdapter(adapter);
			if (mAdapter != null)
			{
				mOldItemCount = mItemCount;
				mItemCount = mAdapter.getCount();
				mDataChanged = true;
				checkFocus();
				mDataSetObserver = new android.widget.AbsListView.AdapterDataSetObserver(this);
				mAdapter.registerDataSetObserver(mDataSetObserver);
				mRecycler.setViewTypeCount(mAdapter.getViewTypeCount());
				int position;
				if (mStackFromBottom)
				{
					position = lookForSelectablePosition(mItemCount - 1, false);
				}
				else
				{
					position = lookForSelectablePosition(0, true);
				}
				setSelectedPositionInt(position);
				setNextSelectedPositionInt(position);
				checkSelectionChanged();
			}
			else
			{
				checkFocus();
				// Nothing selected
				checkSelectionChanged();
			}
			requestLayout();
		}