2

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>
tven
  • 547
  • 6
  • 18

1 Answers1

3

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

Engr Waseem Arain
  • 1,163
  • 1
  • 17
  • 36
  • Would not let me edit my comment earlier. And i pressed return key too soon. Anyway, http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/ is what i was looking for exactly. Thanks for the pointer to Android Hive. Really nice resource. XML parsing and http calls in the main thread is a red flag for anyone trying to copy this to production code. Should use Async task, or use a lib like Volley. – tven May 06 '14 at 05:13