1

Hi i am trying to show two item in list view.i know we can do this with the following. ArrayList<Map<String, String>> but i need to show one image along with this two item.
Here is a image which I want.

enter image description here

I create xml file with one imageview and two text view.i don't understand how to do this.

tshepang
  • 12,111
  • 21
  • 91
  • 136
Sandip Armal Patil
  • 6,241
  • 21
  • 93
  • 160
  • 1
    check http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/ how it works fine? – Samir Mangroliya Apr 14 '12 at 10:32
  • 1
    http://geekswithblogs.net/bosuch/archive/2012/02/24/android-tutorialndashadding-images-to-your-custom-multi-line-listview.aspx – confucius Apr 14 '12 at 10:33

6 Answers6

2

You should implement the class ArrayAdapter and create your own ListAdapter.

See: http://www.vogella.com/articles/AndroidListView/article.html

jenzz
  • 7,239
  • 6
  • 49
  • 69
NotCamelCase
  • 1,073
  • 1
  • 10
  • 18
1

You need to create a Layout file with your cell design. In the Adapter, then you get a View from the Layout programmatically calling the current layout inflate method, and fill the fields and return it.

SJuan76
  • 24,532
  • 6
  • 47
  • 87
  • Hi Sandip, You should create custom ListView to display images and text together. To display images, you require Lazy Loading. – Krishna Suthar Apr 14 '12 at 10:59
1

Here is a implementation of such a list: Contact-Picture-Sync

Heinrisch
  • 5,835
  • 4
  • 33
  • 43
1

For me the way to do it is using BaseAdapter. You need to have the list view on the activity, one xml for the item layout and then on the listview call the setAdapter() with the adapter.

You can find some info here: Lazy Load images on Listview in android(Beginner Level)?

Community
  • 1
  • 1
Nuno Gonçalves
  • 6,202
  • 7
  • 46
  • 66
1

firt of all you should use an ArrayList with an own object like

Class MyListeItem {

    String text1;
    String text2;
    String image;
}

List<MyListItem> = new ArrayList<MyListItem>();

then create create a class extending BaseAdapter which holds the list. create an xml-file ie. "my_listitem" in the res/layouts folder and in the getView() method of the BaseAdapter do something like

LinearLayout layout =  (LinearLayout)View.inflate(context, R.layout.my_listitem, null);
Andreas Linden
  • 12,489
  • 7
  • 51
  • 67
0

here is a list item xml layout file you can use with the simplest attributes

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:minHeight="?android:attr/listPreferredItemHeight"
    android:orientation="horizontal"
    android:padding="16dp">

    <ImageView
        android:id="@+id/list_item_icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher"/>

    <LinearLayout
        android:layout_height="wrap_content"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:orientation="vertical"
        android:paddingLeft="16dp">

        <TextView
            android:id="@+id/list_item_date_textview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Tomorrow"/>

        <TextView
            android:id="@+id/list_item_forecast_textview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Clear"/>

    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:id="@+id/list_item_high_textview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="25°"/>

        <TextView
            android:id="@+id/list_item_low_textview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="6°"/>
    </LinearLayout>

</LinearLayout>

this will appear like this

enter image description here

and you can remove the last nested LinearLayout to match your requirement

and here are the invisible boundaries enter image description here

Basheer AL-MOMANI
  • 14,473
  • 9
  • 96
  • 92