I would like to know if it's possible to customize each row of listview? I want to add checkboxes to few of the rows, button for another, etc. How to build *.xml file for this?
Thanks in advance!
I would like to know if it's possible to customize each row of listview? I want to add checkboxes to few of the rows, button for another, etc. How to build *.xml file for this?
Thanks in advance!
You can write a normal layout file like the following:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/lineItem">
<!-- The attribute name -->
<TextView android:id="@+id/attributeName" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_alignParentLeft="true"
android:textStyle = "bold" android:paddingTop = "2dp" android:textSize="16dp"/>
<!-- The attribute value just beneath the attribute name -->
<TextView android:id="@+id/attributeValue" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_alignParentLeft="true"
android:layout_below="@id/attributeName" android:textSize="12dp" android:paddingBottom="2dp" />
<!-- Now create button besides the line with right align -->
<Button android:layout_width="wrap_content"
android:background="@drawable/printbutton"
android:layout_height="wrap_content"
android:id="@+id/printbtn"
android:layout_centerInParent="true" android:layout_alignParentBottom="true"></Button>
</RelativeLayout>
Then in your listview adapter function
public View getView(final int position, View convertView, ViewGroup parent)
you can use the line
convertView = mInflater.inflate(R.layout.listviewrow,null);
This is what i have done.
RFTM Android custom components and binding data to a view
That leads to creating a custom Adapter (probably from ListAdapter
or ArrayAdapter
).
You can also start with a ListActivity.
Yeah!It's possible to customize each row with a your layout.(also with CheckBox) You need to develop a custom ArrayAdapter. You may find a tutorial here:
I hope it will be useful for you.