-1

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!

Ziem
  • 6,579
  • 8
  • 53
  • 86
  • 1
    Yes its possible .you can search web there are numerous tutorials for this.You will be wasting your time for someone to answer. – Its not blank Dec 14 '11 at 12:25
  • http://stackoverflow.com/questions/8476217/two-views-in-each-list-item/8476380#8476380 The principle's the same. – Jave Dec 14 '11 at 12:28

3 Answers3

1

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.

Bekar
  • 53
  • 1
  • 5
1

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.

rds
  • 26,253
  • 19
  • 107
  • 134
0

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.

Jav_Rock
  • 22,059
  • 20
  • 123
  • 164