Measure height in the presence of a width

Stephen Paul Weber created

So that wrapping text, etc, is taken in to account

Change summary

src/cheogram/java/com/cheogram/android/Util.java | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

Detailed changes

src/cheogram/java/com/cheogram/android/Util.java 🔗

@@ -1,6 +1,7 @@
 package com.cheogram.android;
 
 import android.view.View;
+import android.view.View.MeasureSpec;
 import android.view.ViewGroup;
 import android.widget.ListView;
 import android.widget.ListAdapter;
@@ -14,9 +15,11 @@ public class Util {
 		}
 		ViewGroup vg = listView;
 		int totalHeight = 0;
+		final int width = listView.getWidth() > 0 ? listView.getWidth() : listView.getContext().getResources().getDisplayMetrics().widthPixels;
+		final int widthSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST);
 		for (int i = 0; i < adapter.getCount(); i++) {
 			View listItem = adapter.getView(i, null, vg);
-			listItem.measure(0, 0);
+			listItem.measure(widthSpec, 0);
 			totalHeight += listItem.getMeasuredHeight();
 		}