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


Java ListAdapter.getView方法代碼示例

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


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

示例1: measureHeight

import android.widget.ListAdapter; //導入方法依賴的package包/類
private int measureHeight(int measureSpec) {
	int mode = MeasureSpec.getMode(measureSpec);
	if (mode == MeasureSpec.AT_MOST) {
		return MeasureSpec.makeMeasureSpec(measureSpec, mode);
	} else if (mode == MeasureSpec.EXACTLY) {
		ListAdapter adapter = getAdapter();
		if (adapter == null) {
			measureSpec = 0;
		} else {
			int result = 0;
			for (int i = 0; i < adapter.getCount(); i++) {
				View contentView = adapter.getView(i, null, null);
				contentView.measure(0, 0);
				result += contentView.getMeasuredHeight();
			}
			measureSpec = result + getDividerHeight()
					* (adapter.getCount() - 1);
		}
	}

	return MeasureSpec.makeMeasureSpec(measureSpec, mode);
}
 
開發者ID:NewCasino,項目名稱:browser,代碼行數:23,代碼來源:SuperListView.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: 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:Lazyeraser,項目名稱:DereHelper,代碼行數:19,代碼來源:Utils.java

示例4: setListViewHeightBasedOnChildren

import android.widget.ListAdapter; //導入方法依賴的package包/類
/**
 * @param listView
 * @author sunglasses
 * @category 計算listview高度
 */
public static void setListViewHeightBasedOnChildren(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:TAnsz,項目名稱:MyTvLauncher,代碼行數:24,代碼來源:Tools.java

示例5: setListViewHeightBasedOnChildren

import android.widget.ListAdapter; //導入方法依賴的package包/類
/**
 * 動態設置ListView的高度
 * @param listView ListView
 */
public static void setListViewHeightBasedOnChildren(ListView listView) {
    if(listView == null) return;

    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:wzx54321,項目名稱:XinFramework,代碼行數:25,代碼來源:ViewFinder.java

示例6: getView

import android.widget.ListAdapter; //導入方法依賴的package包/類
/**
 * Get a View that displays the data at the specified
 * position in the data set.
 *
 * @param position    Position of the item whose data we want
 * @param convertView View to recycle, if not null
 * @param parent      ViewGroup containing the returned View
 */
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    for (ListAdapter piece : getPieces()) {
        int size = piece.getCount();

        if (position < size) {

            return (piece.getView(position, convertView, parent));
        }

        position -= size;
    }

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

示例7: setListViewHeightBasedOnChildren

import android.widget.ListAdapter; //導入方法依賴的package包/類
public static void setListViewHeightBasedOnChildren(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 = 80 * (listAdapter.getCount() - 1);
    // params.height = 80 * (listAdapter.getCount());
    params.height = totalHeight
            + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
    ((ViewGroup.MarginLayoutParams) params).setMargins(0, 0, 0, 0);
    listView.setLayoutParams(params);

}
 
開發者ID:Zyj163,項目名稱:yyox,代碼行數:21,代碼來源:ExpandedListUtils.java

示例8: 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

示例9: 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

示例10: setListViewHeightBasedOnChildren

import android.widget.ListAdapter; //導入方法依賴的package包/類
/***
 * 動態設置listview的高度
 * 
 * @param listView
 */
public void setListViewHeightBasedOnChildren(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));
	// params.height += 5;// if without this statement,the listview will be
	// a
	// little short
	// listView.getDividerHeight()獲取子項間分隔符占用的高度
	// params.height最後得到整個ListView完整顯示需要的高度
	listView.setLayoutParams(params);
}
 
開發者ID:qizhenghao,項目名稱:HiBangClient,代碼行數:27,代碼來源:EditSchoolActivity.java

示例11: setGridViewHeightByChildren

import android.widget.ListAdapter; //導入方法依賴的package包/類
/**
 * 根據子item的高度 動態測量GridView的實際高度
 * @param gridView
 */
public static void setGridViewHeightByChildren(GridView gridView) {
    ListAdapter listAdapter = gridView.getAdapter();
    if (listAdapter == null) {
        return;
    }
    //總高度
    int totalHeight = 0;
    int lineNum = gridView.getNumColumns(); //得到布局文件中設置的一行顯示幾個
    View item = listAdapter.getView(0,null,gridView);
    item.measure(0,0); //計算子item的高度
    //得到總高度
    totalHeight = item.getMeasuredHeight()*lineNum;

    ViewGroup.LayoutParams params = gridView.getLayoutParams();
    params.height = totalHeight;
    gridView.setLayoutParams(params);
}
 
開發者ID:yinyiliang,項目名稱:RabbitCloud,代碼行數:22,代碼來源:SmallToolsHelper.java

示例12: getListViewParams

import android.widget.ListAdapter; //導入方法依賴的package包/類
/**
 * 動態的算出ListView實際的LayoutParams 最關鍵的是算出LayoutParams.height
 */
private void getListViewParams() {
    // 通過ListView獲取其中的適配器adapter
    ListAdapter listAdapter = lv_res.getAdapter();
    if (listAdapter == null) {
        return;
    }
    // 聲明默認高度為0
    int totalHeight = 0;
    // 遍曆listView中所有Item,累加所有item的高度就是ListView的實際高度(後麵會考慮分割線的高度)
    for (int i = 0; i < listAdapter.getCount(); i++) {
        View item = listAdapter.getView(i, null, lv_res);
        item.measure(0, 0);
        totalHeight += item.getMeasuredHeight();
    }
    ViewGroup.LayoutParams lp = lv_res.getLayoutParams();
    lp.height = totalHeight
            + (lv_res.getDividerHeight() * (listAdapter.getCount() - 1));
    lv_res.setLayoutParams(lp);
}
 
開發者ID:android-app-development-course,項目名稱:fruit,代碼行數:23,代碼來源:EyeResultActivity.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: setListViewHeightBasedOnChildren

import android.widget.ListAdapter; //導入方法依賴的package包/類
public static void setListViewHeightBasedOnChildren(ListView listView) {
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter != null) {
        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();
        }
        LayoutParams params = listView.getLayoutParams();
        params.height = (listView.getDividerHeight() * (listAdapter.getCount() - 1)) +
                totalHeight;
        listView.setLayoutParams(params);
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:16,代碼來源:ListViewUtils.java

示例15: getWrapHeight

import android.widget.ListAdapter; //導入方法依賴的package包/類
/**
 * 計算 ListView 自適應高度
 * @param listView
 * @return
 */
public static int getWrapHeight(ListView listView){
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null) {
        return 0;
    }
    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();
    }
    totalHeight += (listView.getDividerHeight() * (listAdapter.getCount() - 1));
    return totalHeight;
}
 
開發者ID:42Chapters,項目名稱:AdaptationX-android,代碼行數:20,代碼來源:ListViewManager.java


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