38 lines
980 B
Java
38 lines
980 B
Java
|
////////////////////////////////////////////////
|
||
|
//
|
||
|
// 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();
|
||
|
if( old_count > 0 )
|
||
|
params.height = ( getCount() * getChildAt(0).getHeight() ) + 20;
|
||
|
else
|
||
|
params.height = 0;
|
||
|
setLayoutParams(params);
|
||
|
}
|
||
|
|
||
|
super.onDraw(canvas);
|
||
|
}
|
||
|
}
|