Android custom layout listview with images -
i manage obtain listview dynamic items. built row_layout containing imageview, , 2 textviews. when build adapter, want able display imageview or not depending on row number. want have img1 on row 2, img2 on row 3, img3 on row 5. , on other rows not want imageview displayed (and alignment of textviews must change filling empty space left imageview missing).
is possible?
i populate adapter here:
jsonobject json_data; try { int length = lststat.length(); detalii_client = new client[length]; (int = 0; < length; i++) { json_data = lststat.getjsonobject(i); detalii_client[i] = new client(); string categoria = json_data.getstring("den"); if ("1".equals(categoria)){ // row 1 detalii_client[i].desc ="some title"; detalii_client[i].icon = 0; // here want no image } if ("2".equals(categoria)){ // row 2 detalii_client[i].desc ="some other title"; detalii_client[i].icon = 0; // here want assign picture imageview } .... i have class:
public class client { public int icon; public string desc; public string title; public string id; public client(){ super(); } public client(int icon, string desc, string title, string id) { super(); this.icon = icon; this.desc = desc; this.id = id; this.title= title; } } and custom adapter class
public class clientadapter extends arrayadapter<client>{ context context; int layoutresourceid; client data[] = null; public clientadapter(context context, int layoutresourceid, client[] 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; clientholder holder = null; if(row == null) { layoutinflater inflater = ((activity)context).getlayoutinflater(); row = inflater.inflate(layoutresourceid, parent, false); holder = new clientholder(); holder.hldicon = (imageview)row.findviewbyid(r.id.imgiconx); holder.hldtitle = (textview)row.findviewbyid(r.id.txttitlu); holder.hlddesc = (textview)row.findviewbyid(r.id.txtdescr); holder.hldid = (textview)row.findviewbyid(r.id.txtid); row.settag(holder); } else { holder = (clientholder)row.gettag(); } client clientul = data[position]; holder.hldtitle.settext(clientul.title); holder.hlddesc.settext(clientul.desc); holder.hldid.settext(clientul.id); holder.hldicon.setimageresource(clientul.icon); return row; } static class clientholder { imageview hldicon; textview hldtitle; textview hldid; textview hlddesc; } } also have activity layout (irrelevant) 1 listview , bottom button (relativelayout). , have row_layout use display rows.
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <imageview android:id="@+id/imgiconx" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/client64" /> <linearlayout android:layout_width="145dp" android:layout_height="match_parent" android:layout_weight="1.50" android:orientation="vertical" > <textview android:id="@+id/txtdescr" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margintop="10dp" android:text="@string/lbl_loc" android:textcolor="@color/darkred" android:textsize="@dimen/descriere_detaliu" android:typeface="serif" /> <textview android:id="@+id/txttitlu" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/lbl_client" android:textappearance="?android:attr/textappearancelarge" android:textcolor="@color/darkred" android:textsize="18sp" android:textstyle="normal" android:typeface="serif" /> <textview android:id="@+id/txtid" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/lbl_idviz" android:textappearance="?android:attr/textappearancesmall" android:textcolor="@color/white" /> </linearlayout> </relativelayout> - where can assign pictures imageview?
- and how can make imageview "disappear" rows?
thank you
where can assign pictures imageview?
do in getview() method of adapter. looks doing now.
and how can make imageview "disappear" rows?
use anif statement , if isn't correct row (position) call
holder.hldicon.setvisibility(view.invisible)` or
holder.hldicon.setvisibility(view.gone) depending on want
Comments
Post a Comment