當前位置: 首頁>>代碼示例>>Java>>正文


Java ListAdapter.getCount方法代碼示例

本文整理匯總了Java中android.widget.ListAdapter.getCount方法的典型用法代碼示例。如果您正苦於以下問題:Java ListAdapter.getCount方法的具體用法?Java ListAdapter.getCount怎麽用?Java ListAdapter.getCount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.widget.ListAdapter的用法示例。


在下文中一共展示了ListAdapter.getCount方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setListViewHeightBasedOnChildren

import android.widget.ListAdapter; //導入方法依賴的package包/類
/**
 * Taken from Stack Overflow - https://stackoverflow.com/a/26501296
 * Updates the ListView height based on its children
 *
 * @param listView the ListView to adjust
 */

public static void setListViewHeightBasedOnChildren(ListView listView) {
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null) {
        // pre-condition
        return;
    }

    int totalHeight = 0;
    int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.AT_MOST);
    for (int i = 0; i < listAdapter.getCount(); i++) {
        View listItem = listAdapter.getView(i, null, listView);
        listItem.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED);
        totalHeight += listItem.getMeasuredHeight();
    }

    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
    listView.setLayoutParams(params);
    listView.requestLayout();
}
 
開發者ID:jthomperoo,項目名稱:Forge,代碼行數:28,代碼來源:GeneratorFragment.java

示例2: setListViewHeightBasedOnChildren

import android.widget.ListAdapter; //導入方法依賴的package包/類
/**
 * @Title: setListViewHeightBasedOnChildren @Description:
 * TODO(根據ListView算出List的高度) @param @param mContext @param @param
 * listView 參數 @return void 返回類型 @throws
 */
public static void setListViewHeightBasedOnChildren(Context mContext, ListView listView) {
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null) {
        return;
    }

    int totalHeight = 0;
    for (int i = 0; i < listAdapter.getCount(); i++) {
        View listItem = listAdapter.getView(i, null, listView);
        listItem.measure(0, 0);
        totalHeight += listItem.getMeasuredHeight();
    }
    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
    listView.setLayoutParams(params);
}
 
開發者ID:junchenChow,項目名稱:exciting-app,代碼行數:22,代碼來源:Utils.java

示例3: findFirstVisibleSectionPosition

import android.widget.ListAdapter; //導入方法依賴的package包/類
int findFirstVisibleSectionPosition(int firstVisibleItem, int visibleItemCount) {
	ListAdapter adapter = getAdapter();

       int adapterDataCount = adapter.getCount();
       if (getLastVisiblePosition() >= adapterDataCount) return -1; // dataset has changed, no candidate

       if (firstVisibleItem+visibleItemCount >= adapterDataCount){//added to prevent index Outofbound (in case)
           visibleItemCount = adapterDataCount-firstVisibleItem;
       }

	for (int childIndex = 0; childIndex < visibleItemCount; childIndex++) {
		int position = firstVisibleItem + childIndex;
		int viewType = adapter.getItemViewType(position);
		if (isItemViewTypePinned(adapter, viewType)) return position;
	}
	return -1;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:PinnedSectionListView.java

示例4: setListViewHeightBasedOnChildren

import android.widget.ListAdapter; //導入方法依賴的package包/類
/**
 * 計算ListView的高度, 重置ListView的高度.
 * 
 * @param listView
 */
public static void setListViewHeightBasedOnChildren(ListView listView)
{
	ListAdapter listAdapter = listView.getAdapter();
	if (listAdapter == null)
	{
		return;
	}

	View listItem = null;
	int totalHeight = 0;
	for (int i = 0; i < listAdapter.getCount(); i++)
	{
		listItem = listAdapter.getView(i, null, listView);
		listItem.measure(0, 0);
		totalHeight += listItem.getMeasuredHeight();
	}

	ViewGroup.LayoutParams params = listView.getLayoutParams();
	params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
	listView.setLayoutParams(params);
}
 
開發者ID:benniaobuguai,項目名稱:android-project-gallery,代碼行數:27,代碼來源:ViewUtils.java

示例5: setListViewHeightBasedOnChildren

import android.widget.ListAdapter; //導入方法依賴的package包/類
public static void setListViewHeightBasedOnChildren(ListView listView)
{
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null)
    {
        // pre-condition
        return;
    }
    
    int totalHeight = 0;
    for (int i = 0; i < listAdapter.getCount(); i++)
    {
        View listItem = listAdapter.getView(i, null, listView);
        listItem.measure(0, 0);
        totalHeight += listItem.getMeasuredHeight();
    }
    
    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
    listView.setLayoutParams(params);
}
 
開發者ID:zhuyu1022,項目名稱:amap,代碼行數:22,代碼來源:MIP_ListViewHeight.java

示例6: setListViewHeightBasedOnChildren

import android.widget.ListAdapter; //導入方法依賴的package包/類
/**
 * 修正listview高度
 */
public static void setListViewHeightBasedOnChildren(ListView listView) {
    // 獲取ListView對應的Adapter
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null) {
        return;
    }
    int totalHeight = 0;
    for (int i = 0; i < listAdapter.getCount(); i++) { // listAdapter.getCount()返回數據項的數目
        View listItem = listAdapter.getView(i, null, listView);
        listItem.measure(0, 0); // 計算子項View 的寬高
        totalHeight += listItem.getMeasuredHeight(); // 統計所有子項的總高度
    }
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, totalHeight
            + (listView.getDividerHeight() * (listAdapter.getCount() - 1)));
    listView.setLayoutParams(lp);
}
 
開發者ID:wzc25151,項目名稱:lrs_android,代碼行數:20,代碼來源:DisplayUtil.java

示例7: getItem

import android.widget.ListAdapter; //導入方法依賴的package包/類
/**
 * Get the data item associated with the specified
 * position in the data set.
 *
 * @param position Position of the item whose data we want
 */
@Override
public Object getItem(int position)
{
	for (ListAdapter piece : pieces)
	{
		int size = piece.getCount();

		if (position < size)
		{
			return (piece.getItem(position));
		}

		position -= size;
	}

	return (null);
}
 
開發者ID:ultrasonic,項目名稱:ultrasonic,代碼行數:24,代碼來源:MergeAdapter.java

示例8: getItemViewType

import android.widget.ListAdapter; //導入方法依賴的package包/類
/**
 * Get the type of View that will be created by getView()
 * for the specified item.
 *
 * @param position Position of the item whose data we want
 */
@Override
public int getItemViewType(int position)
{
	int typeOffset = 0;
	int result = -1;

	for (ListAdapter piece : pieces)
	{
		int size = piece.getCount();

		if (position < size)
		{
			result = typeOffset + piece.getItemViewType(position);
			break;
		}

		position -= size;
		typeOffset += piece.getViewTypeCount();
	}

	return (result);
}
 
開發者ID:ultrasonic,項目名稱:ultrasonic,代碼行數:29,代碼來源:MergeAdapter.java

示例9: getSectionForPosition

import android.widget.ListAdapter; //導入方法依賴的package包/類
@Override
public int getSectionForPosition(int position) {
    int section = 0;

    for (ListAdapter piece : getPieces()) {
        int size = piece.getCount();

        if (position < size) {
            if (piece instanceof SectionIndexer) {
                return (section + ((SectionIndexer) piece).getSectionForPosition(position));
            }

            return (0);
        } else {
            if (piece instanceof SectionIndexer) {
                Object[] sections = ((SectionIndexer) piece).getSections();

                if (sections != null) {
                    section += sections.length;
                }
            }
        }

        position -= size;
    }

    return (0);
}
 
開發者ID:Twelvelines,項目名稱:AndroidMuseumBleManager,代碼行數:29,代碼來源:MergeAdapter.java

示例10: testSelectUser

import android.widget.ListAdapter; //導入方法依賴的package包/類
public void testSelectUser(){
    solo.clickOnView(getActivity().getBottomBarTabFromId(R.id.tab_search));
    solo.sleep(1000);

    ListAdapter adapter = ((ListView)solo.getView(R.id.searchUsersList)).getAdapter();
    if (adapter.getCount() > 0) {
        solo.clickInList(1, 0);
        solo.sleep(2000);
        assertTrue("wrong fragment", getActivity().getFragmentForCurrentTab() instanceof SearchUsersFragment);
    }
}
 
開發者ID:CMPUT301F17T15,項目名稱:CIA,代碼行數:12,代碼來源:SearchUsersIntentTests.java

示例11: recreatePinnedShadow

import android.widget.ListAdapter; //導入方法依賴的package包/類
void recreatePinnedShadow() {
  destroyPinnedShadow();
  ListAdapter adapter = getAdapter();
  if (adapter != null && adapter.getCount() > 0) {
    // JACOB: Fix for crash
    int firstVisiblePosition = Math.min(getFirstVisiblePosition(), adapter.getCount() - 1);
    int sectionPosition = findCurrentSectionPosition(firstVisiblePosition);
    if (sectionPosition == -1) return; // no views to pin, exit
    ensureShadowForPosition(sectionPosition,
        firstVisiblePosition, getLastVisiblePosition() - firstVisiblePosition);
  }
}
 
開發者ID:nordfalk,項目名稱:EsperantoRadio,代碼行數:13,代碼來源:PinnedSectionListView.java

示例12: measureWidthOfChildren

import android.widget.ListAdapter; //導入方法依賴的package包/類
final int measureWidthOfChildren(int heightMeasureSpec, int startPosition, int endPosition, int maxWidth, int disallowPartialChildPosition) {
    ListAdapter adapter = this.mAdapter;
    if (adapter == null) {
        return this.mListPadding.left + this.mListPadding.right;
    }
    int returnedWidth = this.mListPadding.left + this.mListPadding.right;
    int dividerWidth = (this.mDividerWidth <= 0 || this.mDivider == null) ? 0 : this.mDividerWidth;
    int prevWidthWithoutPartialChild = 0;
    if (endPosition == -1) {
        endPosition = adapter.getCount() - 1;
    }
    RecycleBin recycleBin = this.mRecycler;
    boolean recyle = recycleOnMeasure();
    boolean[] isScrap = this.mIsScrap;
    int i = startPosition;
    while (i <= endPosition) {
        View child = obtainView(i, isScrap);
        measureScrapChildWidth(child, i, heightMeasureSpec);
        if (i > 0) {
            returnedWidth += dividerWidth;
        }
        if (recyle && recycleBin.shouldRecycleViewType(((LayoutParams) child.getLayoutParams()).viewType)) {
            recycleBin.addScrapView(child, -1);
        }
        returnedWidth += child.getMeasuredWidth();
        if (returnedWidth < maxWidth) {
            if (disallowPartialChildPosition >= 0 && i >= disallowPartialChildPosition) {
                prevWidthWithoutPartialChild = returnedWidth;
            }
            i++;
        } else if (disallowPartialChildPosition < 0 || i <= disallowPartialChildPosition || prevWidthWithoutPartialChild <= 0 || returnedWidth == maxWidth) {
            return maxWidth;
        } else {
            return prevWidthWithoutPartialChild;
        }
    }
    return returnedWidth;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:39,代碼來源:HListView.java

示例13: measureHeight

import android.widget.ListAdapter; //導入方法依賴的package包/類
private int measureHeight() {
    // get ListView adapter
    ListAdapter adapter = mListView.getAdapter();
    if (null == adapter) {
        return 0;
    }

    int totalHeight = 0;

    for (int i = 0, len = adapter.getCount(); i < len; i++) {
        View item = adapter.getView(i, null, mListView);
        if (null == item) continue;
        // measure each item width and height
        item.measure(0, 0);
        // calculate all height
        totalHeight += item.getMeasuredHeight();
    }

    ViewGroup.LayoutParams params = mListView.getLayoutParams();

    if (null == params) {
        params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
    }

    // calculate ListView height
    params.height = totalHeight + (mListView.getDividerHeight() * (adapter.getCount() - 1));

    mListView.setLayoutParams(params);

    return params.height;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:33,代碼來源:XScrollViewActivity.java

示例14: setGridViewHeightBasedOnChildren

import android.widget.ListAdapter; //導入方法依賴的package包/類
public static void setGridViewHeightBasedOnChildren(GridView listView,int col) {
	// 獲取listview的adapter
	ListAdapter listAdapter = listView.getAdapter();
	if (listAdapter == null) {
		return;
	}
	// 固定列寬,有多少列
	int totalHeight = 0;
	// i每次加4,相當於listAdapter.getCount()小於等於4時 循環一次,計算一次item的高度,
	// listAdapter.getCount()小於等於8時計算兩次高度相加
	for (int i = 0; i < listAdapter.getCount(); i += col) {
		// 獲取listview的每一個item
		View listItem = listAdapter.getView(i, null, listView);
		listItem.measure(0, 0);
		// 獲取item的高度和
		totalHeight += listItem.getMeasuredHeight();
		totalHeight += listView.getVerticalSpacing();
		if (i==listAdapter.getCount()-1) {
			totalHeight += listView.getVerticalSpacing();
		}
	}
	// 獲取listview的布局參數
	LayoutParams params = listView.getLayoutParams();
	// 設置高度
	params.height = totalHeight;
	// 設置margin
	((MarginLayoutParams) params).setMargins(10, 10, 10, 10);
	// 設置參數
	listView.setLayoutParams(params);
}
 
開發者ID:Jay-Ping,項目名稱:newIPlay,代碼行數:31,代碼來源:FixedViewUtil.java

示例15: onFocusChanged

import android.widget.ListAdapter; //導入方法依賴的package包/類
protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
    super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
    int closetChildIndex = -1;
    if (gainFocus && previouslyFocusedRect != null) {
        previouslyFocusedRect.offset(getScrollX(), getScrollY());
        ListAdapter adapter = this.mAdapter;
        if (adapter.getCount() < getChildCount() + this.mFirstPosition) {
            this.mLayoutMode = 0;
            layoutChildren();
        }
        Rect otherRect = this.mTempRect;
        int minDistance = ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_UNLIMITED;
        int childCount = getChildCount();
        int firstPosition = this.mFirstPosition;
        for (int i = 0; i < childCount; i++) {
            if (adapter.isEnabled(firstPosition + i)) {
                View other = getChildAt(i);
                other.getDrawingRect(otherRect);
                offsetDescendantRectToMyCoords(other, otherRect);
                int distance = PLA_AbsListView.getDistance(previouslyFocusedRect, otherRect,
                        direction);
                if (distance < minDistance) {
                    minDistance = distance;
                    closetChildIndex = i;
                }
            }
        }
    }
    if (closetChildIndex >= 0) {
        setSelection(this.mFirstPosition + closetChildIndex);
    } else {
        requestLayout();
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:35,代碼來源:PLA_ListView.java


注:本文中的android.widget.ListAdapter.getCount方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。