Search in sources :

Example 71 with ListAdapter

use of android.widget.ListAdapter in project android by owncloud.

the class ShareFileFragment method setListViewHeightBasedOnChildren.

public static void setListViewHeightBasedOnChildren(ListView listView) {
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null) {
        return;
    }
    int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.AT_MOST);
    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, ViewGroup.LayoutParams.WRAP_CONTENT));
        }
        view.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED);
        totalHeight += view.getMeasuredHeight();
    }
    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
    listView.setLayoutParams(params);
    listView.requestLayout();
}
Also used : ViewGroup(android.view.ViewGroup) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) ListView(android.widget.ListView) ShareUserListAdapter(com.owncloud.android.ui.adapter.ShareUserListAdapter) ListAdapter(android.widget.ListAdapter)

Example 72 with ListAdapter

use of android.widget.ListAdapter in project android by owncloud.

the class GridViewWithHeaderAndFooter method removeFooterView.

/**
     * Removes a previously-added footer view.
     *
     * @param v The view to remove
     * @return true if the view was removed, false if the view was not a header
     * view
     */
public boolean removeFooterView(View v) {
    if (mFooterViewInfos.size() > 0) {
        boolean result = false;
        ListAdapter adapter = getAdapter();
        if (adapter != null && ((HeaderViewGridAdapter) adapter).removeFooter(v)) {
            result = true;
        }
        removeFixedViewInfo(v, mFooterViewInfos);
        return result;
    }
    return false;
}
Also used : ListAdapter(android.widget.ListAdapter) WrapperListAdapter(android.widget.WrapperListAdapter)

Example 73 with ListAdapter

use of android.widget.ListAdapter in project android by owncloud.

the class GridViewWithHeaderAndFooter method removeHeaderView.

/**
     * Removes a previously-added header view.
     *
     * @param v The view to remove
     * @return true if the view was removed, false if the view was not a header
     * view
     */
public boolean removeHeaderView(View v) {
    if (mHeaderViewInfos.size() > 0) {
        boolean result = false;
        ListAdapter adapter = getAdapter();
        if (adapter != null && ((HeaderViewGridAdapter) adapter).removeHeader(v)) {
            result = true;
        }
        removeFixedViewInfo(v, mHeaderViewInfos);
        return result;
    }
    return false;
}
Also used : ListAdapter(android.widget.ListAdapter) WrapperListAdapter(android.widget.WrapperListAdapter)

Example 74 with ListAdapter

use of android.widget.ListAdapter in project android by owncloud.

the class GridViewWithHeaderAndFooter method onMeasure.

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    ListAdapter adapter = getAdapter();
    if (adapter != null && adapter instanceof HeaderViewGridAdapter) {
        ((HeaderViewGridAdapter) adapter).setNumColumns(getNumColumnsCompatible());
        invalidateRowHeight();
        ((HeaderViewGridAdapter) adapter).setRowHeight(getRowHeight());
    }
}
Also used : ListAdapter(android.widget.ListAdapter) WrapperListAdapter(android.widget.WrapperListAdapter)

Example 75 with ListAdapter

use of android.widget.ListAdapter in project QLibrary by DragonsQC.

the class ListViewUtil method setListViewHeightBasedOnChildren.

public static void setListViewHeightBasedOnChildren(ListView listView) {
    //获取ListView对应的Adapter
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null) {
        // pre-condition
        return;
    }
    int totalHeight = 0;
    for (int i = 0, len = listAdapter.getCount(); i < len; i++) {
        //listAdapter.getCount()返回数据项的数目
        View listItem = listAdapter.getView(i, null, listView);
        //计算子项View 的宽高
        listItem.measure(0, 0);
        //统计所有子项的总高度
        totalHeight += listItem.getMeasuredHeight();
    }
    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
    //listView.getDividerHeight()获取子项间分隔符占用的高度
    //params.height最后得到整个ListView完整显示需要的高度
    listView.setLayoutParams(params);
}
Also used : ViewGroup(android.view.ViewGroup) View(android.view.View) ListView(android.widget.ListView) ListAdapter(android.widget.ListAdapter)

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