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


Java ListView.getAdapter方法代碼示例

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


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

示例1: resizeListView

import android.widget.ListView; //導入方法依賴的package包/類
private void resizeListView(ListView listView, boolean isBottomList) {
    ListAdapter adapter = listView.getAdapter();
    int count = adapter.getCount();
    int itemsHeight = 0;
    // Your views have the same layout, so all of them have
    // the same height
    View oneChild = listView.getChildAt(0);
    if (oneChild == null) {
        return;
    }
    itemsHeight = oneChild.getHeight();
    // Resize your list view
    LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) listView.getLayoutParams();
    params.height = isBottomList ? itemsHeight * count + itemsHeight / 2 : itemsHeight * count;
    listView.setLayoutParams(params);
}
 
開發者ID:Adyen,項目名稱:adyen-android,代碼行數:17,代碼來源:PaymentMethodSelectionFragment.java

示例2: setListViewHeightBasedOnChildren

import android.widget.ListView; //導入方法依賴的package包/類
private 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:stytooldex,項目名稱:pius1,代碼行數:22,代碼來源:MaterialDialog.java

示例3: getListViewMesureHeight

import android.widget.ListView; //導入方法依賴的package包/類
public static int getListViewMesureHeight(ListView lv) {
    int height = 0;

    try {
        ListAdapter la = lv.getAdapter();
        int count = la.getCount();

        for (int i = 0; i < count; ++i) {
            View listItem = la.getView(i, (View) null, lv);
            listItem.measure(View.MeasureSpec.makeMeasureSpec(0, 0), View.MeasureSpec.makeMeasureSpec(0, 0));
            height += listItem.getMeasuredHeight();
        }

        height += lv.getDividerHeight() * (count - 1);
    } catch (Exception var6) {
        ;
    }

    return height;
}
 
開發者ID:Tamicer,項目名稱:FilterBar,代碼行數:21,代碼來源:UIUtil.java

示例4: setListViewHeightBasedOnChildren

import android.widget.ListView; //導入方法依賴的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);
}
 
開發者ID:benniaobuguai,項目名稱:android-project-gallery,代碼行數:27,代碼來源:ViewUtils.java

示例5: addItem

import android.widget.ListView; //導入方法依賴的package包/類
private void addItem(Activity activity, String name, Integer value)
{
    ShadowActivity shadowActivity = shadowOf(activity);
    ListView list = (ListView)activity.findViewById(R.id.list);
    assertNotNull(list);

    int initialCount = list.getCount();

    shadowActivity.clickMenuItem(R.id.action_add);
    ItemizationAdapter adapter = (ItemizationAdapter)list.getAdapter();
    Itemization listItem = adapter.getItem(initialCount);
    assertNotNull(listItem);
    listItem.name = name;
    listItem.value = value;

    assertEquals(initialCount+1, list.getCount());
}
 
開發者ID:brarcher,項目名稱:rental-calc,代碼行數:18,代碼來源:ItemizationActivityTest.java

示例6: setAdapterHeight

import android.widget.ListView; //導入方法依賴的package包/類
public static void setAdapterHeight(ListView listView){

        android.widget.ListAdapter listAdapter = listView.getAdapter();//1、獲取adapter
        if (listAdapter == null) {
            return;
        }

        int totalHeight = 0;
        for (int i = 0,j =listAdapter.getCount(); i < j ; i++) {  //2、算出沒一個item高度總和
            View listItem = listAdapter.getView(i , null, listView);
            listItem.measure(0, 0);
            totalHeight += listItem.getMeasuredHeight();
        }

        ViewGroup.LayoutParams params=listView.getLayoutParams();
        params.height = totalHeight + listView.getPaddingBottom()   //3、加上listview自身每行間距屬性
                + listView.getPaddingTop()
                + (listView.getDividerHeight() * (listAdapter.getCount() - 1));


        listView.setLayoutParams(params);//4、重新設置高
    }
 
開發者ID:aiyangtianci,項目名稱:BluetoothAPP,代碼行數:23,代碼來源:ListViewHeightMesure.java

示例7: setListViewHeightBasedOnChildren

import android.widget.ListView; //導入方法依賴的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

示例8: setListViewHeightBasedOnChildren

import android.widget.ListView; //導入方法依賴的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

示例9: setListViewHeightBasedOnChildren

import android.widget.ListView; //導入方法依賴的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,代碼來源:EditProvinceActivity.java

示例10: setListViewHeightBasedOnChildren

import android.widget.ListView; //導入方法依賴的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

示例11: getWrapHeight

import android.widget.ListView; //導入方法依賴的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

示例12: setListViewHeightBasedOnChildren

import android.widget.ListView; //導入方法依賴的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,項目名稱:letv,代碼行數:15,代碼來源:LetvUtil.java

示例13: refreshListView

import android.widget.ListView; //導入方法依賴的package包/類
public void refreshListView() {
	ListView listView = (ListView) findViewById(R.id.browser_elements);

	TGBrowserListAdapter tgBrowserElementAdapter = (TGBrowserListAdapter) listView.getAdapter();
	TGBrowserSession tgBrowserSession = TGBrowserManager.getInstance(this.findContext()).getSession();
	if (tgBrowserSession.getCurrentElements() == null) {
		tgBrowserElementAdapter.clearElements();
	} else {
		tgBrowserElementAdapter.fillElements(tgBrowserSession.getCurrentElements());
	}
	
	tgBrowserElementAdapter.notifyDataSetChanged();
}
 
開發者ID:axlecho,項目名稱:tuxguitar,代碼行數:14,代碼來源:TGBrowserView.java

示例14: onResume

import android.widget.ListView; //導入方法依賴的package包/類
@Override
protected void onResume() {
    super.onResume();

    ListView lvData = (ListView) findViewById(R.id.listData);
    ListDataAdapter adapter = (ListDataAdapter) lvData.getAdapter();
    adapter.refresh();
}
 
開發者ID:mnirfan,項目名稱:kuliah-pemrograman-mobile,代碼行數:9,代碼來源:MainActivity.java

示例15: setListViewHeightBasedOnItems

import android.widget.ListView; //導入方法依賴的package包/類
public static boolean setListViewHeightBasedOnItems(ListView listView) {

        ListAdapter listAdapter = listView.getAdapter();
        if (listAdapter != null) {

            int numberOfItems = listAdapter.getCount();

            // Get total height of all items.
            int totalItemsHeight = 0;
            for (int itemPos = 0; itemPos < numberOfItems; itemPos++) {
                View item = listAdapter.getView(itemPos, null, listView);
                item.measure(0, 0);
                totalItemsHeight += item.getMeasuredHeight();
            }

            // Get total height of all item dividers.
            int totalDividersHeight = listView.getDividerHeight() *
                    (numberOfItems - 1);

            int topPAdding = listView.getPaddingTop();
            int bottomPadding = listView.getPaddingBottom();

            // Set list height.
            ViewGroup.LayoutParams params = listView.getLayoutParams();
            params.height = totalItemsHeight + totalDividersHeight + topPAdding + bottomPadding;
            listView.setLayoutParams(params);
            listView.requestLayout();

            return true;

        } else {
            return false;
        }

    }
 
開發者ID:aliumujib,項目名稱:Orin,代碼行數:36,代碼來源:ViewUtil.java


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