Android ListView layout param set -
i have listview in xml. structure of that:
<listview android:id="@+id/seriescastlistitemview" android:paddingtop="10dip" android:layout_width="fill_parent" android:layout_height="fill_parent" android:divider="#ffffff" android:dividerheight="1px"/>
now want set height listview
java code. tried following code.
listview castlistitemview = (listview) findviewbyid(r.id.seriescastlistitemview); castlistitemview.setadapter(new castadapter(this, castdescriptionarr)); castlistitemview.setlayoutparams(new listview.layoutparams(layoutparams.fill_parent, 500));
but giving java.lang.classcastexception: android.widget.abslistview$layoutparams
. problem in code?
you should using layoutparams of parent view contains listview. in case, placed listview in frame layout, , used code. if placed listview in linearlayout use linearlayout.layoutparams.
listview castlistitemview = (listview) findviewbyid(r.id.seriescastlistitemview); castlistitemview.setadapter(new castadapter(this, castdescriptionarr)); castlistitemview.setlayoutparams(new framelayout.layoutparams(framelayout.layoutparams.fill_parent, 500));
i assume typo in question, make sure "c" in castlistitemview lowercase on third line.
mrjre brings point though. because many different views have own layoutparams, best include view parameters wish use (as in framelayout.layoutparams) instead of making eclipse guess based on layoutparams class imported.
you can see previous question more information.
Comments
Post a Comment