for @AlexanderAgeichenko Here is my implementation with @baradas and the question
int totalItemsHeight = 0; float px = (customListView.getResources().getDisplayMetrics().density); totalItemsHeight = (int)px; Log.d(YOUR_TAG, " datta forloop ... px " + px); Log.d(YOUR_TAG, " datta forloop ... totalItemsHeight = (int)px= " + totalItemsHeight); for (int itemPos = 0; itemPos < datta.length(); itemPos++) { View item = CustomListAdptr.getView(itemPos, null, customListView); //// item.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), //// View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); item.getMeasuredHeightAndState(); Log.d(YOUR_TAG, " datta forloop item.getHeight() " + item.getHeight()); Log.d(YOUR_TAG, " datta forloop item.getMeasuredHeight() " + item.getMeasuredHeight()); Log.d(YOUR_TAG, " datta forloop item.getMeasuredHeightAndState() " + item.getMeasuredHeightAndState()); int itmHeight = item.getHeight(); Log.d(YOUR_TAG, " datta forloop ... itmHeight " + itmHeight); item.measure(View.MeasureSpec.makeMeasureSpec((int)px, View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); totalItemsHeight = item.getMeasuredHeight(); // Log.d(YOUR_TAG, " datta forloop ... item.getMeasuredHeight() " + item.getMeasuredHeight()); Log.d(YOUR_TAG, " datta forloop ... totalItemsHeight=item.getMeasuredHeight() " + totalItemsHeight); } Log.d(YOUR_TAG, " datta forloop ... totalItemsHeight == " + totalItemsHeight); // Get total height of all item dividers. int totalDividersHeight = customListView.getDividerHeight() * (numberOfItems - 1); // Get padding int totalPadding = customListView.getPaddingTop() + customListView.getPaddingBottom(); // Set list height. ViewGroup.LayoutParams params = customListView.getLayoutParams(); params.height = totalItemsHeight + totalDividersHeight + totalPadding; customListView.setLayoutParams(params); customListView.requestLayout(); customListView.canScrollList(0);
And was delivered
D/YOUR_TAG: onViewCompleted() if(success) setting the list data D/YOUR_TAG: datta counts 3 D/YOUR_TAG: datta forloop ... px 2.0 D/YOUR_TAG: datta forloop ... totalItemsHeight = (int)px= 2 D/YOUR_TAG: datta forloop item.getMeasuredHeightAndState() 0 D/YOUR_TAG: datta forloop item.getMeasuredHeight() 0 D/YOUR_TAG: datta forloop item.getHeight() 0 D/YOUR_TAG: datta forloop ... itmHeight 0 D/YOUR_TAG: datta forloop ... totalItemsHeight=item.getMeasuredHeight() 1709 D/YOUR_TAG: datta forloop item.getMeasuredHeightAndState() 0 D/YOUR_TAG: datta forloop item.getMeasuredHeight() 0 D/YOUR_TAG: datta forloop item.getHeight() 0 D/YOUR_TAG: datta forloop ... itmHeight 0 D/YOUR_TAG: datta forloop ... totalItemsHeight=item.getMeasuredHeight() 1709 D/YOUR_TAG: datta forloop item.getMeasuredHeightAndState() 0 D/YOUR_TAG: datta forloop item.getMeasuredHeight() 0 D/YOUR_TAG: datta forloop item.getHeight() 0 D/YOUR_TAG: datta forloop ... itmHeight 0 D/YOUR_TAG: datta forloop ... totalItemsHeight=item.getMeasuredHeight() 1709 D/YOUR_TAG: datta forloop ... totalItemsHeight == 1709 D/YOUR_TAG: getView() -> unit_option= 0 :: class java.lang.String
With 110 float px = 110 * (customListView.getResources (). GetDisplayMetrics (). Density);
D/YOUR_TAG: onViewCompleted() if(success) setting the list data D/YOUR_TAG: datta counts 3 D/YOUR_TAG: datta forloop ... px 220.0 D/YOUR_TAG: datta forloop ... totalItemsHeight = (int)px= 220 D/YOUR_TAG: datta forloop item.getMeasuredHeightAndState() 0 D/YOUR_TAG: datta forloop item.getMeasuredHeight() 0 D/YOUR_TAG: datta forloop item.getHeight() 0 D/YOUR_TAG: datta forloop ... itmHeight 0 D/YOUR_TAG: datta forloop ... totalItemsHeight=item.getMeasuredHeight() 159 D/YOUR_TAG: datta forloop item.getMeasuredHeightAndState() 0 D/YOUR_TAG: datta forloop item.getMeasuredHeight() 0 D/YOUR_TAG: datta forloop item.getHeight() 0 D/YOUR_TAG: datta forloop ... itmHeight 0 D/YOUR_TAG: datta forloop ... totalItemsHeight=item.getMeasuredHeight() 159 D/YOUR_TAG: datta forloop item.getMeasuredHeightAndState() 0 D/YOUR_TAG: datta forloop item.getMeasuredHeight() 0 D/YOUR_TAG: datta forloop item.getHeight() 0 D/YOUR_TAG: datta forloop ... itmHeight 0 D/YOUR_TAG: datta forloop ... totalItemsHeight=item.getMeasuredHeight() 159 D/YOUR_TAG: datta forloop ... totalItemsHeight == 159
source share