Custom adapter for a list of items that have multiple child items?

瘦欲@ 提交于 2019-11-26 23:32:56

问题


How would i go about writing an adapter for this Layout. I started out wanting to making a list using linear and relative layout, so that each list item has child items align horizontally relative to each other. Here is the layout file and the screenshot of the view.

I understand how to write simple list views and adapters. But just wondering how i can get to more complex lists with more than hand full of child list items.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/trade_scenario_linear_main"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="#8a929d">
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="?android:attr/listPreferredItemHeight"
        android:padding="6dip"
        android:background="#e8e7e2">

        <ImageView
            android:id="@+id/avatar"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_alignParentBottom="true"
            android:layout_alignParentTop="true"
            android:contentDescription="TODO"
            android:src="@drawable/avatar_temp" />

        <TextView
            android:id="@+id/username"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_alignWithParentIfMissing="true"
            android:layout_toRightOf="@id/avatar"
            android:text="Shepherd"
            android:textColor="#ED872D"
            android:textSize="12sp" />

        <ImageView
            android:id="@+id/clock_icon"
            android:layout_width="16dp"
            android:layout_height="16dp"
            android:layout_marginLeft="90dp"
            android:layout_gravity="right"
            android:layout_toRightOf="@id/username"
            android:src="@drawable/clock_icon" />
        <TextView
            android:id="@+id/clock_data"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/clock_icon"
            android:textSize="14sp"
            android:text="22H 30mins"/>

        <ImageView
            android:id="@+id/comments_icon"
            android:layout_width="16dp"
            android:layout_height="16dp"
            android:layout_alignParentBottom="true"
            android:layout_toRightOf="@id/avatar"
            android:src="@drawable/comment" />

        <TextView
            android:id="@+id/comments_num"
            android:layout_width="wrap_content"
            android:layout_height="26dip"
            android:layout_alignParentBottom="true"
            android:layout_alignTop="@+id/comments_icon"
            android:layout_toRightOf="@id/comments_icon"
            android:ellipsize="marquee"
            android:singleLine="true"
            android:text="14"
            android:textSize="12sp" />

    </RelativeLayout> 
</LinearLayout>

回答1:


Create custom listiew and also create the custom adapter, like that follow that Tutorials that help you: Custom Listviews also follow that more essier List View



来源:https://stackoverflow.com/questions/23485986/custom-adapter-for-a-list-of-items-that-have-multiple-child-items

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