android - Avoid duplication of ImageButton in Listview -
i newbie in android & developing first ever app of personal diary. having problem in listview, have imagebutton in 1 layout want behave header , have textviews in layout representing listview bound database. problem many rows database many button generating don't want. using list activity generating listview out of textviews.
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginbottom="2dp" android:layout_weight="1" android:orientation="vertical" android:padding="2dp" android:weightsum="2" > <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/detail_title_bar_2" android:orientation="horizontal" android:layout_marginbottom="5dp" > <imagebutton android:id="@+id/btnadd" android:layout_width="40dp" android:layout_height="40dp" android:layout_gravity="bottom" android:src="@drawable/add" /> </linearlayout> <linearlayout android:layout_width="90dp" android:layout_height="wrap_content" android:background="@drawable/detail_title_bar_2" android:orientation="vertical" android:paddingright="10dp" > <textview android:id="@+id/txtday" style="@style/title_day" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:layout_marginbottom="-10dp" android:includefontpadding="false" android:verticalspacing="0px" /> <textview android:id="@+id/txtmonth" style="@style/title_month" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:layout_marginbottom="-10dp" android:includefontpadding="false" android:verticalspacing="0px" /> <textview android:id="@+id/txtyear" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" /> <textview android:id="@+id/txttime" style="@style/title_time" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" /> </linearlayout> </linearlayout>
as understanded question, have listview filled entries loaded database und want button @ top of list e.g. add new items?
then can use addheaderview() function. define layout containing image button xml layout file, e.g. list_header_view.xml , add listview:
view headerview = (view)inflater.inflate( r.layout.list_header_view, null); listview.addheaderview(headerview);
list_header_view.xml can contain:
<linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/detail_title_bar_2" android:orientation="horizontal" android:layout_marginbottom="5dp" > <imagebutton android:id="@+id/btnadd" android:layout_width="40dp" android:layout_height="40dp" android:layout_gravity="bottom" android:src="@drawable/add" /> </linearlayout>
Comments
Post a Comment