i followed this tutorial on how add header, text view id/txttitle
, , image view id/imgicon
individual list elements within list view.
i modified tutorial code incorporate third text view id/txttitle2
, still see image view id/imgicon
, original text view id/txttitle
. additionally, list view seems it's bigger, or zoomed in. result of code modifications.
how can fix code see third text view without size distortion?
activity_main.xml
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingleft="0dp" android:paddingright="0dp" android:paddingtop="0dp" android:paddingbottom="0dp" tools:context=".mainactivity"> <listview android:id="@+id/listview1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_alignparentbottom="true" android:layout_alignparentleft="true" android:layout_alignparentstart="true" /> </relativelayout>
listview_item_row.xml
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="10dp"> <imageview android:id="@+id/imgicon" android:layout_width="wrap_content" android:layout_height="fill_parent" android:gravity="center_vertical" android:layout_alignparenttop="true" android:layout_alignparentbottom="true" android:layout_marginright="15dp" android:layout_margintop="5dp" android:layout_marginbottom="5dp" /> <textview android:id="@+id/txttitle" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center_vertical" android:layout_alignparenttop="true" android:layout_alignparentbottom="true" android:textstyle="bold" android:textsize="22dp" android:textcolor="#000000" android:layout_margintop="5dp" android:layout_marginbottom="5dp" /> <textview android:id="@+id/txttitle2" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center_vertical" android:layout_alignparenttop="true" android:layout_alignparentbottom="true" android:textstyle="bold" android:textsize="22dp" android:textcolor="#000000" android:layout_margintop="5dp" android:layout_marginbottom="5dp" /> </linearlayout>
custom list adapter weatheradapter extends arrayadapter<weather>
public class weatheradapter extends arrayadapter<weather>{ context context; int layoutresourceid; weather data[] = null; public weatheradapter(context context, int layoutresourceid, weather[] data) { super(context, layoutresourceid, data); this.layoutresourceid = layoutresourceid; this.context = context; this.data = data; } @override public view getview(int position, view convertview, viewgroup parent) { view row = convertview; weatherholder holder = null; if(row == null) { layoutinflater inflater = ((activity)context).getlayoutinflater(); row = inflater.inflate(layoutresourceid, parent, false); holder = new weatherholder(); holder.imgicon = (imageview)row.findviewbyid(r.id.imgicon); holder.txttitle = (textview)row.findviewbyid(r.id.txttitle); holder.txttitle2 = (textview)row.findviewbyid(r.id.txttitle2); row.settag(holder); } else { holder = (weatherholder)row.gettag(); } weather weather = data[position]; holder.txttitle2.settext(weather.title2); holder.txttitle.settext(weather.title); holder.imgicon.setimageresource(weather.icon); return row; } static class weatherholder { imageview imgicon; textview txttitle; textview txttitle2; } }
class weather
public class weather { public int icon; public string title; public string title2; public weather(){ super(); } public weather(int icon, string title, string title2) { super(); this.icon = icon; this.title = title; this.title2 = title2; } }
in row layout both 2nd , 3rd text views have width set fill _ parent.. in scenario, 2nd textview takes entire width of screen, , 3rd textview has no space left.. change attributes wrap_content, or use weights instead..
Comments
Post a Comment