I am trying to show elements in a list view using Fragments. I created my custom view as follow
graphical representation of list_row.xml
list_row.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dip" >
<!-- ListRow Left sied Thumbnail image -->
<LinearLayout
android:id="@+id/thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dip"
android:padding="3dip" >
<ImageView
android:id="@+id/list_image"
android:layout_width="50dip"
android:layout_height="50dip"
android:contentDescription="@string/image_desc"/>
</LinearLayout>
<!-- Menu name -->
<TextView
android:id="@+id/menu_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/thumbnail"
android:layout_toRightOf="@+id/thumbnail"
android:text="@string/menu_name"
android:textColor="#040404"
android:textSize="15sp"
android:textStyle="bold"
android:typeface="sans" />
<!-- Description -->
<TextView
android:id="@+id/description"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/thumbnail"
android:layout_below="@id/menu_name"
android:layout_marginTop="1dip"
android:layout_toRightOf="@+id/thumbnail"
android:text="@string/description"
android:textColor="#343434"
android:textSize="10sp"
tools:ignore="SmallSp" />
<!-- Price -->
<TextView
android:id="@+id/price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@id/menu_name"
android:layout_marginRight="5dip"
android:gravity="right"
android:text="@string/price"
android:textColor="#10bcc9"
android:textSize="10sp"
android:textStyle="bold"
tools:ignore="SmallSp" />
</RelativeLayout>
In fragment.xml file, I simply put a list view inside a linear layout
fragment.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
</LinearLayout>
I have an array of menu objects, that has the necessary fields to populate list_row.xml like menu name, description, price and image. I couldn't find a way to fill fragment.xml's listView with the list_row elements. Any help or idea would be appreciated.
PS: I think in fragment.xml instead of android:id="@+id/listView1"
field, I have to write android:id="@id/list"
since I'm using ListFragment