Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Height of ListView at run time in android

How to set Height of ListView.

XML Code (This code is working fine and fixed height as 200 dip)

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="5dip"
    android:orientation="vertical" >
    <ListView
        android:id="@+id/dialog_ListView"
        android:layout_width="wrap_content"
        android:layout_height="200dip"
        android:padding="5dip"
        android:layout_weight="1"
        android:dividerHeight="5dip"
        android:divider="@android:color/transparent" />        
</LinearLayout>

Android Code (This code not fixed width and height)

convertView = mInflater.inflate( R.layout.dialog_page, null );
convertView.setLayoutParams( new ListView.LayoutParams( 200, 300) );

Android Code (This code i got Error Message)

convertView = mInflater.inflate( R.layout.lock_file_page, parent );
convertView.setLayoutParams( new ListView.LayoutParams( 200, 300) );

Error Message

java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView

How do fix Width and Height at Runtime.

Thanks in advance.

like image 425
Sekar Avatar asked Jul 13 '12 07:07

Sekar


1 Answers

Try This code..

 LayoutParams lp = (LayoutParams) mListView.getLayoutParams();
 lp.height = 300;
 mListView.setLayoutParams(lp);
like image 79
Mehul Santoki Avatar answered Nov 15 '22 10:11

Mehul Santoki