本文整理汇总了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();
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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);
}
示例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();
}
}