i have problem how hide button in specific row in listview simpleadapter
. sample code.
alert_noti_layout.xml
<?xml version="1.0" encoding="utf-8"?> <listview xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/listview1" android:layout_width="fill_parent" android:layout_height="fill_parent" > </listview>
alert_pop_list.xml
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <textview android:id="@+id/view1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="view1" android:textsize="20dp" android:textstyle="bold" android:layout_alignparenttop="true" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:layout_toleftof="@+id/confirm" android:layout_tostartof="@+id/confirm" /> <textview android:id="@+id/view2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="textview" android:textsize="10dp" android:textstyle="bold" android:visibility="visible" android:layout_below="@+id/view1" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:layout_toleftof="@+id/confirm" android:layout_tostartof="@+id/confirm" /> <button style="?android:attr/buttonstylesmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/confirm" android:layout_alignbottom="@+id/view2" android:layout_alignparenttop="true" android:layout_alignparentright="true" android:layout_alignparentend="true" android:background="@drawable/ic_confirm" /> </relativelayout>
activity :
list<map<string, string>> listdata = new arraylist<map<string, string>>(); map<string, object> names = new hashmap<string, object>(); names.put("first","head1"); names.put("second", "txt1"); names.put("first","head2"); names.put("second", "txt2"); names.put("first","head3"); names.put("second", "txt3"); ... listdata.add((hashmap) names); listview lv = (listview) dialog_mail.findviewbyid(r.id.listview1); // arrayadapter<string> adapter = new arrayadapter<string>(home.this,, android.r.layout.two_line_list_item, names); simpleadapter adapter = new simpleadapter(home.this, listdata, r.layout.alert_pop_list, new string[] {"first", "second" }, new int[] {r.id.view1, r.id.view2}); lv.setadapter(adapter);
how hide button if value head2
, show rest of list.
you need custom baseadapter
instead of simpleadapter
, write code @ getview()
method。 like:
public view getview(int p,view view,viewgroup parent) { if (view == null) { view = layoutinflate.xxxx; } button btn = (button) view.findviewbyid(r.id.btn); datamodel d = list.get(p); if (d.ishidden || d.data.equals("head2")) { btn.setvisibility(view.gone); } else { btn.setvisibility(view.visible); } return view; }
so need create datamodel
store property.
public class datamodel { public boolean ishidden; public hashmap<string,string> datamap; //and on..... }