List view with image and two item?

…衆ロ難τιáo~ 提交于 2019-12-04 19:30:16
NotCamelCase

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

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

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.

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

Nuno Gonçalves

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)?

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);

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!