set ListView Height Based On Children : ListView « UI « Android

Home
Android
1.2D Graphics
2.Animation
3.Core Class
4.Database
5.Date Type
6.Development
7.File
8.Game
9.Hardware
10.Media
11.Network
12.Security
13.UI
14.User Event
Android » UI » ListView 
set ListView Height Based On Children
   
//package com.omareitti;

import java.util.List;
import java.util.UUID;

import android.app.Activity;
import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Parcelable;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.ListView;

public class Utils {

    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(00);
            totalHeight += listItem.getMeasuredHeight();
        }

        ViewGroup.LayoutParams params = listView.getLayoutParams();
        params.height = totalHeight + (listView.getDividerHeight() (listAdapter.getCount() 1));
        listView.setLayoutParams(params);
        listView.requestLayout();
    }
  


}

   
    
    
  
Related examples in the same category
1.Using ExpandableListView
2.Using ListView
3.Using SimpleAdapter to fill data to ListView
4.Custom cell Renderer for ListView
5.Provide xml layout for ListView Item
6.Fill contact information to ListView
7.ListView.CHOICE_MODE_MULTIPLE
8.Use AbsListView OnScrollListener(AbsListView.OnScrollListener), AbsListView#setOnItemScrollListener(AbsListView.OnItemScrollListener)} to display the first letter of the visible range of cheeses.
9.This demo illustrates the use of CHOICE_MODE_MULTIPLE_MODAL, a.k.a. selection mode on ListView.
10.FileList extends ListView
11.Adding a List
12.Lunch List
13.Get Item index in item click event
14.On nothing selected event
15.Create List
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.