2012-09-06 23:08:46 +05:30
|
|
|
////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// A ChaloBEST (http://chalobest.in/) initiative
|
|
|
|
// Author: Vivek (Macgregor Techknowlogy)
|
|
|
|
// License: GPLv3
|
|
|
|
//
|
|
|
|
//
|
|
|
|
package com.best.ui;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.graphics.Canvas;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.widget.ListView;
|
|
|
|
|
|
|
|
public class ExpandedListView extends ListView {
|
|
|
|
|
|
|
|
private android.view.ViewGroup.LayoutParams params;
|
|
|
|
private int old_count = 0;
|
|
|
|
|
|
|
|
public ExpandedListView(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onDraw(Canvas canvas) {
|
|
|
|
if (getCount() != old_count) {
|
|
|
|
old_count = getCount();
|
|
|
|
params = getLayoutParams();
|
2012-10-25 20:15:46 +05:30
|
|
|
params.height = 0;
|
2012-09-06 23:08:46 +05:30
|
|
|
if( old_count > 0 )
|
2012-10-25 20:15:46 +05:30
|
|
|
{
|
|
|
|
for(int i = 0; i < getCount(); i++)
|
|
|
|
{
|
|
|
|
System.out.println("===getCount()"+getCount()+"==="+i);
|
|
|
|
try{
|
|
|
|
params.height += getChildAt(i).getHeight();
|
|
|
|
}catch(Exception e){
|
|
|
|
System.out.println( "ERROR in getHeight:"+i );
|
|
|
|
params.height += 75;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
params.height += 20;
|
|
|
|
//params.height = ( getCount() * getChildAt(0).getHeight() ) + 20;
|
|
|
|
System.out.println("====Child Height===="+getChildAt(0).getHeight());
|
|
|
|
System.out.println("====List View Height===="+params.height);
|
|
|
|
}
|
2012-09-06 23:08:46 +05:30
|
|
|
else
|
|
|
|
params.height = 0;
|
|
|
|
setLayoutParams(params);
|
|
|
|
}
|
2012-10-25 20:15:46 +05:30
|
|
|
|
2012-09-06 23:08:46 +05:30
|
|
|
super.onDraw(canvas);
|
|
|
|
}
|
|
|
|
}
|