Search in sources :

Example 46 with ListAdapter

use of android.widget.ListAdapter in project Lazy by l123456789jy.

the class ViewUtils method getAbsListViewHeightBasedOnChildren.

/**
     * get AbsListView height according to every children
     *
     * @param view view
     * @return int
     */
public static int getAbsListViewHeightBasedOnChildren(AbsListView view) {
    ListAdapter adapter;
    if (view == null || (adapter = view.getAdapter()) == null) {
        return 0;
    }
    int height = 0;
    for (int i = 0; i < adapter.getCount(); i++) {
        View item = adapter.getView(i, null, view);
        if (item instanceof ViewGroup) {
            item.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        }
        item.measure(0, 0);
        height += item.getMeasuredHeight();
    }
    height += view.getPaddingTop() + view.getPaddingBottom();
    return height;
}
Also used : LayoutParams(android.widget.RelativeLayout.LayoutParams) ViewGroup(android.view.ViewGroup) GridView(android.widget.GridView) AbsListView(android.widget.AbsListView) TextView(android.widget.TextView) View(android.view.View) ListView(android.widget.ListView) ListAdapter(android.widget.ListAdapter) Point(android.graphics.Point)

Example 47 with ListAdapter

use of android.widget.ListAdapter in project SmartAndroidSource by jaychou2012.

the class DragListView method getChildHeight.

private int getChildHeight(int position) {
    if (position == mSrcPos) {
        return 0;
    }
    View v = getChildAt(position - getFirstVisiblePosition());
    if (v != null) {
        // hence the "true"
        return getChildHeight(position, v, false);
    } else {
        // item is offscreen
        // first check cache for child height at this position
        int childHeight = mChildHeightCache.get(position);
        if (childHeight != -1) {
            // Log.d("mobeta", "found child height in cache!");
            return childHeight;
        }
        final ListAdapter adapter = getAdapter();
        int type = adapter.getItemViewType(position);
        // There might be a better place for checking for the following
        final int typeCount = adapter.getViewTypeCount();
        if (typeCount != mSampleViewTypes.length) {
            mSampleViewTypes = new View[typeCount];
        }
        if (type >= 0) {
            if (mSampleViewTypes[type] == null) {
                v = adapter.getView(position, null, this);
                mSampleViewTypes[type] = v;
            } else {
                v = adapter.getView(position, mSampleViewTypes[type], this);
            }
        } else {
            // type is HEADER_OR_FOOTER or IGNORE
            v = adapter.getView(position, null, this);
        }
        // current child height is invalid, hence "true" below
        childHeight = getChildHeight(position, v, true);
        // cache it because this could have been expensive
        mChildHeightCache.add(position, childHeight);
        return childHeight;
    }
}
Also used : View(android.view.View) AbsListView(android.widget.AbsListView) ListView(android.widget.ListView) Point(android.graphics.Point) ListAdapter(android.widget.ListAdapter)

Example 48 with ListAdapter

use of android.widget.ListAdapter in project SmartAndroidSource by jaychou2012.

the class Common method onScrollStateChanged2.

private void onScrollStateChanged2(AbsListView lv, int scrollState) {
    lv.setTag(AQuery.TAG_NUM, scrollState);
    if (scrollState == SCROLL_STATE_IDLE) {
        int first = lv.getFirstVisiblePosition();
        int last = lv.getLastVisiblePosition();
        int count = last - first;
        ListAdapter la = lv.getAdapter();
        for (int i = 0; i <= count; i++) {
            long packed = i + first;
            View convertView = lv.getChildAt(i);
            Number targetPacked = (Number) convertView.getTag(AQuery.TAG_NUM);
            if (targetPacked != null) {
                la.getView((int) packed, convertView, lv);
                convertView.setTag(AQuery.TAG_NUM, null);
            } else {
            //AQUtility.debug("skip!");
            }
        }
    }
}
Also used : AbsListView(android.widget.AbsListView) View(android.view.View) AdapterView(android.widget.AdapterView) ExpandableListView(android.widget.ExpandableListView) ExpandableListAdapter(android.widget.ExpandableListAdapter) ListAdapter(android.widget.ListAdapter)

Example 49 with ListAdapter

use of android.widget.ListAdapter in project android-common by Trinea.

the class ViewUtils method getListViewHeightBasedOnChildren.

/**
     * get ListView height according to every children
     * 
     * @param view
     * @return
     */
public static int getListViewHeightBasedOnChildren(ListView view) {
    int height = getAbsListViewHeightBasedOnChildren(view);
    ListAdapter adapter;
    int adapterCount;
    if (view != null && (adapter = view.getAdapter()) != null && (adapterCount = adapter.getCount()) > 0) {
        height += view.getDividerHeight() * (adapterCount - 1);
    }
    return height;
}
Also used : ListAdapter(android.widget.ListAdapter)

Example 50 with ListAdapter

use of android.widget.ListAdapter in project SeriesGuide by UweTrottmann.

the class HeaderGridView method addHeaderView.

/**
     * Add a fixed view to appear at the top of the grid. If addHeaderView is called more than once,
     * the views will appear in the order they were added. Views added using this call can take
     * focus if they want. <p> NOTE: Call this before calling setAdapter. This is so HeaderGridView
     * can wrap the supplied cursor with one that will also account for header views.
     *
     * @param v The view to add.
     * @param data Data to associate with this view
     * @param isSelectable whether the item is selectable
     */
public void addHeaderView(View v, Object data, boolean isSelectable) {
    ListAdapter adapter = getAdapter();
    if (adapter != null && !(adapter instanceof HeaderViewGridAdapter)) {
        throw new IllegalStateException("Cannot add header view to grid -- setAdapter has already been called.");
    }
    FixedViewInfo info = new FixedViewInfo();
    FrameLayout fl = new FullWidthFixedViewLayout(getContext());
    fl.addView(v);
    info.view = v;
    info.viewContainer = fl;
    info.data = data;
    info.isSelectable = isSelectable;
    mHeaderViewInfos.add(info);
    // we need to notify the observer
    if (adapter != null) {
        ((HeaderViewGridAdapter) adapter).notifyDataSetChanged();
    }
}
Also used : FrameLayout(android.widget.FrameLayout) ListAdapter(android.widget.ListAdapter) WrapperListAdapter(android.widget.WrapperListAdapter)

Aggregations

ListAdapter (android.widget.ListAdapter)298 ListView (android.widget.ListView)105 View (android.view.View)96 AdapterView (android.widget.AdapterView)55 AbsListView (android.widget.AbsListView)48 WrapperListAdapter (android.widget.WrapperListAdapter)47 HeaderViewListAdapter (android.widget.HeaderViewListAdapter)44 TextView (android.widget.TextView)42 ViewGroup (android.view.ViewGroup)37 Paint (android.graphics.Paint)22 ArrayAdapter (android.widget.ArrayAdapter)21 Point (android.graphics.Point)19 SuppressLint (android.annotation.SuppressLint)16 SimpleCursorAdapter (android.widget.SimpleCursorAdapter)16 Cursor (android.database.Cursor)12 SectionIndexer (android.widget.SectionIndexer)11 DialogInterface (android.content.DialogInterface)10 Bundle (android.os.Bundle)10 FrameLayout (android.widget.FrameLayout)10 GridView (android.widget.GridView)10