Search code examples
androidandroid-listviewcustom-lists

How to create this custom list view


I am looking to create a list view which contains a image and 2 textviews and one Button.like in this format

      Textview1   
image Textview2                               Button

in the above format i have created another layout .now i want to inflate this layout onto listview.for images say i have 6 images in the drawable folder named as image_1,image_2,image_3,image_4,image_5,image-6. i am not able to understand from the examples that i have found in google.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<ImageView android:src="@drawable/stub"
    android:layout_height="50sp" android:layout_width="100sp" android:id="@+id/image"
    android:layout_alignParentTop="true" android:layout_alignParentLeft="true"></ImageView>
<Button android:layout_height="wrap_content"
    android:layout_width="wrap_content" android:text="ADD" android:id="@+id/badd"
    android:layout_alignBottom="@+id/textView2"
    android:layout_alignParentRight="true" android:layout_marginRight="15dp"></Button>
<TextView android:layout_height="wrap_content" android:id="@+id/tvname" android:textAppearance="?android:attr/textAppearanceMedium" android:layout_width="wrap_content" android:text="TextView" android:layout_alignParentTop="true" android:layout_centerHorizontal="true"></TextView>
<TextView android:layout_height="wrap_content" android:id="@+id/tvprice" android:layout_width="wrap_content" android:text="TextView" android:layout_alignBottom="@+id/image" android:layout_centerHorizontal="true"></TextView>

Please provide me some android code to achive this.


Solution

  • What you want to do can be achieved using CustomAdapter. Its is the most common thing which is used in android application.

    Below links can be useful for you.

    http://saigeethamn.blogspot.in/2010/04/custom-listview-android-developer.html

    http://geekswithblogs.net/bosuch/archive/2011/01/31/android---create-a-custom-multi-line-listview-bound-to-an.aspx