Android Open Source - FishApp Utils






From Project

Back to project page FishApp.

License

The source code is released under:

Apache License

If you think the Android project FishApp listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.tschuy.fishapp;
/* ww  w  .  j av a2 s .c o  m*/
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)
            return;

        int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.UNSPECIFIED);
        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();
    }
}




Java Source Code List

com.tschuy.fishapp.ApplicationTest.java
com.tschuy.fishapp.MainActivity.java
com.tschuy.fishapp.NavigationDrawerFragment.java
com.tschuy.fishapp.ProductActivity.java
com.tschuy.fishapp.Product.java
com.tschuy.fishapp.Utils.java
com.tschuy.fishapp.VendorActivity.java
com.tschuy.fishapp.VendorListFragment.java
com.tschuy.fishapp.VendorProductListFragment.java
com.tschuy.fishapp.Vendor.java