Java Code Examples for android.widget.ListView.getAdapter()

The following are Jave code examples for showing how to use getAdapter() of the android.widget.ListView class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: adyen-android   File: PaymentMethodSelectionFragment.java   View Source Code Vote up 8 votes
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);
}
 
Example 2
Project: pius1   File: MaterialDialog.java   View Source Code Vote up 6 votes
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);
   }
 
Example 3
Project: FilterBar   File: UIUtil.java   View Source Code Vote up 6 votes
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;
}
 
Example 4
Project: android-project-gallery   File: ViewUtils.java   View Source Code Vote up 6 votes
/**
 * 计算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);
}
 
Example 5
Project: rental-calc   File: ItemizationActivityTest.java   View Source Code Vote up 6 votes
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());
}
 
Example 6
Project: BluetoothAPP   File: ListViewHeightMesure.java   View Source Code Vote up 6 votes
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、重新设置高
    }
 
Example 7
Project: amap   File: MIP_ListViewHeight.java   View Source Code Vote up 6 votes
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);
}
 
Example 8
Project: DereHelper   File: Utils.java   View Source Code Vote up 6 votes
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);
}
 
Example 9
Project: HiBangClient   File: EditProvinceActivity.java   View Source Code Vote up 6 votes
/***
 * 动态设置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);
}
 
Example 10
Project: HiBangClient   File: RegSchoolActivity.java   View Source Code Vote up 6 votes
/***
 * 动态设置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);
}
 
Example 11
Project: HiBangClient   File: RegProvinceActivity.java   View Source Code Vote up 6 votes
/***
 * 动态设置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);
}
 
Example 12
Project: exciting-app   File: Utils.java   View Source Code Vote up 6 votes
/**
 * @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);
}
 
Example 13
Project: AdaptationX-android   File: ListViewManager.java   View Source Code Vote up 5 votes
/**
 * 计算 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;
}
 
Example 14
Project: letv   File: LetvUtil.java   View Source Code Vote up 5 votes
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);
    }
}
 
Example 15
Project: tuxguitar   File: TGBrowserView.java   View Source Code Vote up 5 votes
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();
}
 
Example 16
Project: kuliah-pemrograman-mobile   File: MainActivity.java   View Source Code Vote up 5 votes
@Override
protected void onResume() {
    super.onResume();

    ListView lvData = (ListView) findViewById(R.id.listData);
    ListDataAdapter adapter = (ListDataAdapter) lvData.getAdapter();
    adapter.refresh();
}
 
Example 17
Project: Orin   File: ViewUtil.java   View Source Code Vote up 5 votes
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;
        }

    }
 
Example 18
Project: tuxguitar   File: TGBrowserCollectionsDialog.java   View Source Code Vote up 5 votes
public void refreshListView() {
	ListView listView = (ListView) this.view.findViewById(R.id.browser_collections_dlg_list);
	TGBrowserCollectionsAdapter collectionsAdapter = (TGBrowserCollectionsAdapter) listView.getAdapter();
	
	collectionsAdapter.clearCollections();
	
	Iterator<TGBrowserCollection> collections = TGBrowserManager.getInstance(this.findContext()).getCollections();
	while( collections.hasNext() ) {
		collectionsAdapter.addCollection(collections.next());
	}
	
	collectionsAdapter.notifyDataSetChanged();
}
 
Example 19
Project: ImageClassify   File: ShareUtil.java   View Source Code Vote up 4 votes
/**
 * 分享排行榜截图
 *
 * @param context
 * @param listView
 * @param handler
 */
public static void shareRankShot(final Context context, final ListView listView, final Handler handler) {
    if (context != null && listView != null) {
        CommonAdapter adapter = (CommonAdapter) listView.getAdapter();
        int itemsCount = adapter.getCount();
        int allItemsHeight = 0;
        int itemWidth = 0;
        final List<Bitmap> bitmapList = new ArrayList<Bitmap>();

        //获取ListView的Bitmap集合
        for (int i = 0; i < itemsCount; i++) {
            View childView = adapter.getView(i, null, listView);
            Drawable defaultDrawable = context.getResources().getDrawable(R.mipmap.ic_launcher);
            childView.measure(MeasureSpec.makeMeasureSpec(listView.getWidth(), MeasureSpec.EXACTLY),
                    MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
            itemWidth = childView.getMeasuredWidth();
            childView.layout(0, 0, childView.getMeasuredWidth(), childView.getMeasuredHeight());
            childView.setDrawingCacheEnabled(true);
            childView.buildDrawingCache();
            bitmapList.add(childView.getDrawingCache());
            allItemsHeight += childView.getMeasuredHeight();
        }

        final int finalItemWidth = itemWidth;
        final int finalAllItemsHeight = allItemsHeight;
        //开启子线程合并图片并分享
        new Thread(new Runnable() {
            @Override
            public void run() {
                Bitmap bigBitmap = Bitmap.createBitmap(finalItemWidth, finalAllItemsHeight, Bitmap.Config.ARGB_8888);
                Canvas bigCanvas = new Canvas(bigBitmap);
                Paint paint = new Paint();
                int iHeight = 0;

                for (int i = 0; i < bitmapList.size(); i++) {
                    Bitmap bmp = bitmapList.get(i);
                    bigCanvas.drawBitmap(bmp, 0, iHeight, paint);
                    iHeight += bmp.getHeight();
                    bmp.recycle();
                    bmp = null;
                }

                String screenShotPathName = "";
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss", Locale.CHINA);

                if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
                    //以当前时间作为图片前缀
                    final String screenShotName = Environment.getExternalStorageDirectory().getPath()
                            + File.separator
                            + simpleDateFormat.format(new Date())
                            + "screenshot.png";
                    try {
                        FileOutputStream out = new FileOutputStream(screenShotName);
                        boolean isSaved = bigBitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
                        if (isSaved) {
                            handler.post(new Runnable() {
                                @Override
                                public void run() {
                                    share(context, SHARE_TYPE.SHARE_IMAGE, "我的排名",
                                            "分享排名", screenShotName);
                                }
                            });
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }).start();

    }
}
 
Example 20
Project: Orin   File: ArtistDetailActivity.java   View Source Code Vote up 4 votes
public void setHeightofListViewBasedOnContent(ListView listView) {

        ListAdapter mAdapter = listView.getAdapter();

        int totalHeight = 0;

        for (int i = 0; i < mAdapter.getCount(); i++) {

            totalHeight += getResources().getDimension(R.dimen.item_list_height);
            Log.w("HEIGHT" + i, String.valueOf(totalHeight));

        }

        totalHeight = totalHeight +  (listView.getDividerHeight() * (mAdapter.getCount() - 1)) + listView.getPaddingTop();

        ViewGroup.LayoutParams params = listView.getLayoutParams();
        params.height = totalHeight;
        listView.setLayoutParams(params);
        listView.requestLayout();

    }