android.widget.ListAdapter类的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(215)

本文整理了Java中android.widget.ListAdapter类的一些代码示例,展示了ListAdapter类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ListAdapter类的具体详情如下:
包路径:android.widget.ListAdapter
类名称:ListAdapter

ListAdapter介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

/**** Method for Setting the Height of the ListView dynamically.
 **** Hack to fix the issue of not showing all the items of the ListView
 **** when placed inside a ScrollView  ****/
public static void setListViewHeightBasedOnChildren(ListView listView) {
  ListAdapter listAdapter = listView.getAdapter();
  if (listAdapter == null)
    return;

  int desiredWidth = MeasureSpec.makeMeasureSpec(listView.getWidth(), MeasureSpec.UNSPECIFIED);
  int totalHeight = 0;
  View view = null;
  for (int i = 0; i < listAdapter.getCount(); i++) {
    view = listAdapter.getView(i, view, listView);
    if (i == 0)
      view.setLayoutParams(new ViewGroup.LayoutParams(desiredWidth, LayoutParams.WRAP_CONTENT));

    view.measure(desiredWidth, MeasureSpec.UNSPECIFIED);
    totalHeight += view.getMeasuredHeight();
  }
  ViewGroup.LayoutParams params = listView.getLayoutParams();
  params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
  listView.setLayoutParams(params);
}

代码示例来源:origin: chentao0707/SimplifyReader

@Override
public Object getItem(int position) {
  if (mAdapter != null) {
    List<Object> items = new ArrayList<Object>(mItemsPerRow);
    for (int i = 0; i < mItemsPerRow; ++i) {
      int p = position * mItemsPerRow + i;
      if (p < mAdapter.getCount()) {
        items.add(mAdapter.getItem(p));
      }
    }
    return items;
  }
  return null;
}

代码示例来源:origin: ksoichiro/Android-ObservableScrollView

@Override
public long getItemId(int position) {
  int numHeadersAndPlaceholders = getHeadersCount() * mNumColumns;
  if (mAdapter != null && position >= numHeadersAndPlaceholders) {
    int adjPosition = position - numHeadersAndPlaceholders;
    int adapterCount = mAdapter.getCount();
    if (adjPosition < adapterCount) {
      return mAdapter.getItemId(adjPosition);
    }
  }
  return -1;
}

代码示例来源:origin: stackoverflow.com

LinearLayout layout = ... // Your linear layout.
ListAdapter adapter = ... // Your adapter.

final int adapterCount = adapter.getCount();

for (int i = 0; i < adapterCount; i++) {
 View item = adapter.getView(i, null, null);
 layout.addView(item);
}

代码示例来源:origin: beworker/pinned-section-listview

View pinnedView = getAdapter().getView(position, pinnedShadow.view, PinnedSectionListView.this);
ViewGroup.LayoutParams layoutParams = pinnedView.getLayoutParams();
if (layoutParams == null) {
    layoutParams = generateDefaultLayoutParams();
    pinnedView.setLayoutParams(layoutParams);
pinnedView.measure(ws, hs);
pinnedView.layout(0, 0, pinnedView.getMeasuredWidth(), pinnedView.getMeasuredHeight());
mTranslateY = 0;
pinnedShadow.id = getAdapter().getItemId(position);

代码示例来源:origin: stackoverflow.com

ListAdapter adapter  = listview.getAdapter(); 
int itemscount       = adapter.getCount();
int allitemsheight   = 0;
List<Bitmap> bmps    = new ArrayList<Bitmap>();
  View childView      = adapter.getView(i, null, listview);
  childView.measure(MeasureSpec.makeMeasureSpec(listview.getWidth(), MeasureSpec.EXACTLY), 
      MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
  childView.layout(0, 0, childView.getMeasuredWidth(), childView.getMeasuredHeight());
  childView.setDrawingCacheEnabled(true);
  childView.buildDrawingCache();
Bitmap bigbitmap    = Bitmap.createBitmap(listview.getMeasuredWidth(), allitemsheight, Bitmap.Config.ARGB_8888);
Canvas bigcanvas    = new Canvas(bigbitmap);

代码示例来源:origin: stackoverflow.com

public int measureContentWidth(ListAdapter adapter) {
  int maxWidth = 0;
  int count = adapter.getCount();
  final int widthMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
  final int heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
  View itemView = null;
  for (int i = 0; i < count; i++) {
    itemView = adapter.getView(i, itemView, this);
    itemView.measure(widthMeasureSpec, heightMeasureSpec);
    maxWidth = Math.max(maxWidth, itemView.getMeasuredWidth());
  }
  return maxWidth;
}

代码示例来源:origin: stackoverflow.com

if (heightMode != MeasureSpec.EXACTLY) {
  ListAdapter listAdapter = getAdapter();
  if (listAdapter != null && !listAdapter.isEmpty()) {
    int listPosition = 0;
    for (listPosition = 0; listPosition < listAdapter.getCount()
        && listPosition < MAXIMUM_LIST_ITEMS_VIEWABLE; listPosition++) {
      View listItem = listAdapter.getView(listPosition, null, this);
        listItem.setLayoutParams(new LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
      listItem.measure(widthMeasureSpec, heightMeasureSpec);
      newHeight += listItem.getMeasuredHeight();

代码示例来源:origin: chentao0707/SimplifyReader

private void measureScrapChild(View child, int position, int widthMeasureSpec) {
  LayoutParams p = (LayoutParams) child.getLayoutParams();
  if (p == null) {
    p = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
        ViewGroup.LayoutParams.WRAP_CONTENT, 0);
    child.setLayoutParams(p);
  }
  p.viewType = mAdapter.getItemViewType(position);
  p.forceAdd = true;
  int childWidthSpec = ViewGroup.getChildMeasureSpec(widthMeasureSpec,
      mListPadding.left + mListPadding.right, p.width);
  int lpHeight = p.height;
  int childHeightSpec;
  if (lpHeight > 0) {
    childHeightSpec = MeasureSpec.makeMeasureSpec(lpHeight, MeasureSpec.EXACTLY);
  } else {
    childHeightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
  }
  child.measure(childWidthSpec, childHeightSpec);
}

代码示例来源:origin: stackoverflow.com

private static final int UNBOUNDED = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);

// To calculate the total height of all items in ListView call with items = adapter.getCount()
public static int getItemHeightofListView(ListView listView, int items) {
  ListAdapter adapter = listView.getAdapter();

  int grossElementHeight = 0;
  for (int i = 0; i < items; i++) {
    View childView = adapter.getView(i, null, listView);
    childView.measure(UNBOUNDED, UNBOUNDED);
    grossElementHeight += childView.getMeasuredHeight();
  }
  return grossElementHeight;
}

代码示例来源:origin: stackoverflow.com

listView.setAdapter(new ListAdapter()
    return originalAdapter.getCount();
    return originalAdapter.getItem(id);
    return originalAdapter.getItemId(id);
    return originalAdapter.getItemViewType(id);
    View view = originalAdapter.getView(position, convertView, parent);
    TextView textView = (TextView)view;
    textView.setTypeface(MyFontUtil.getTypeface(MyActivity,MY_DEFAULT_FONT));
    return originalAdapter.getViewTypeCount();
    return originalAdapter.hasStableIds();
    return originalAdapter.isEmpty();
    originalAdapter.registerDataSetObserver(observer);
    originalAdapter.unregisterDataSetObserver(observer);
    return originalAdapter.areAllItemsEnabled();
    return originalAdapter.isEnabled(position);

代码示例来源:origin: facebook/facebook-android-sdk

@Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    int width = getMeasuredWidth();
    int height = 0;
    ListAdapter adapter = getAdapter();
    int count = adapter != null ? adapter.getCount() : 0;
    for (int i = 0; i < count; i++) {
      View childView = adapter.getView(i, null, this);
      childView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
          MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
      height += childView.getMeasuredHeight();
    }
    height += getDividerHeight() * (count-1);
    setMeasuredDimension(width, height);
  }
}

代码示例来源:origin: Neamar/KISS

@Override
public boolean onSingleTapUp(MotionEvent e) {
  // if minimalistic mode is enabled,
  // and we want to display history on touch
  if (isMinimalisticModeEnabled() && prefs.getBoolean("history-onclick", false)) {
    // and we're currently in minimalistic mode with no results,
    // and we're not looking at the app list
    if ((mainActivity.isViewingSearchResults()) && (mainActivity.searchEditText.getText().toString().isEmpty())) {
      if ((mainActivity.list.getAdapter() == null) || (mainActivity.list.getAdapter().isEmpty())) {
        mainActivity.runTask(new HistorySearcher(mainActivity));
      }
    }
  }
  if (isMinimalisticModeEnabledForFavorites()) {
    mainActivity.favoritesBar.setVisibility(View.VISIBLE);
  }
  return super.onSingleTapConfirmed(e);
}

代码示例来源:origin: beworker/pinned-section-listview

@Override
public void setAdapter(ListAdapter adapter) {
  // assert adapter in debug mode
  if (adapter != null) {
    if (!(adapter instanceof PinnedSectionListAdapter))
      throw new IllegalArgumentException("Does your adapter implement PinnedSectionListAdapter?");
    if (adapter.getViewTypeCount() < 2)
      throw new IllegalArgumentException("Does your adapter handle at least two types" +
          " of views in getViewTypeCount() method: items and sections?");
  }
  // unregister observer at old adapter and register on new one
  ListAdapter oldAdapter = getAdapter();
  if (oldAdapter != null) oldAdapter.unregisterDataSetObserver(mDataSetObserver);
  if (adapter != null) adapter.registerDataSetObserver(mDataSetObserver);
  // destroy pinned shadow, if new adapter is not same as old one
  if (oldAdapter != adapter) destroyPinnedShadow();
  super.setAdapter(adapter);
}

代码示例来源:origin: gzu-liyujiang/AndroidPicker

private void fillListRight(int rightEdge, final int dx) {
  while (rightEdge + dx < getWidth()
      && mRightViewIndex < mAdapter.getCount()) {
    View child = mAdapter.getView(mRightViewIndex,
        mRemovedViewQueue.poll(), this);
    addAndMeasureChild(child, -1);
    rightEdge += child.getMeasuredWidth();
    if (mRightViewIndex == mAdapter.getCount() - 1) {
      mMaxX = mCurrentX + rightEdge - getWidth();
    }
    if (mMaxX < 0) {
      mMaxX = 0;
    }
    mRightViewIndex++;
  }
}

代码示例来源:origin: commonsguy/cw-omnibus

@Test
 public void listCount() {
  Assert.assertEquals(25, list.getAdapter().getCount());
 }
}

代码示例来源:origin: Neamar/KISS

@Override
  public void onItemClick(ListAdapter adapter, View view, int position) {
    @StringRes int stringId = ((ListPopup.Item) adapter.getItem(position)).stringId;
    popupMenuClickHandler(view.getContext(), parent, stringId, parentView);
  }
});

代码示例来源:origin: rey5137/material

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
  super.onLayout(changed, l, t, r, b);
  int totalHeight = 0;
  int childCount = getChildCount();
  for(int i = 0; i < childCount; i++)
    totalHeight += getChildAt(i).getMeasuredHeight();
  showDivider(totalHeight > getMeasuredHeight() || (totalHeight == getMeasuredHeight() && getAdapter().getCount() > childCount));
}

代码示例来源:origin: gzu-liyujiang/AndroidPicker

private void fillListLeft(int leftEdge, final int dx) {
  while (leftEdge + dx > 0 && mLeftViewIndex >= 0) {
    View child = mAdapter.getView(mLeftViewIndex,
        mRemovedViewQueue.poll(), this);
    addAndMeasureChild(child, 0);
    leftEdge -= child.getMeasuredWidth();
    mLeftViewIndex--;
    mDisplayOffset -= child.getMeasuredWidth();
  }
}

代码示例来源:origin: chentao0707/SimplifyReader

public void setAdapter(ListAdapter adapter) {
  if (null != mAdapter) {
    mAdapter.unregisterDataSetObserver(mDataSetObserver);
  mOldSelectedRowId = INVALID_ROW_ID;
  if (mAdapter != null) {
    mAreAllItemsSelectable = mAdapter.areAllItemsEnabled();
    mOldItemCount = mItemCount;
    mItemCount = mAdapter.getCount();
    mAdapter.registerDataSetObserver(mDataSetObserver);
    mRecycler.setViewTypeCount(mAdapter.getViewTypeCount());

相关文章