问题
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.

I create xml file with one imageview and two text view.i don't understand how to do this.
回答1:
You should implement the class ArrayAdapter
and create your own ListAdapter
.
See: http://www.vogella.com/articles/AndroidListView/article.html
回答2:
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.
回答3:
Here is a implementation of such a list: Contact-Picture-Sync
回答4:
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)?
回答5:
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);
回答6:
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
and you can remove
the last nested LinearLayout
to match your requirement
and here are the invisible boundaries
来源:https://stackoverflow.com/questions/10152871/list-view-with-image-and-two-item