Füllen Sie die Liste der benutzerdefinierten Ansicht mit ListFragment

Ich versuche, Elemente mithilfe von Fragmenten in einer Listenansicht anzuzeigen. Ich habe meine benutzerdefinierte Ansicht wie folgt erstellt

Grafische Darstellung von 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 der fragment.xml-Datei füge ich einfach eine Listenansicht in ein lineares Layout ein

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>

Ich habe eine Reihe von Menüobjekten, die die erforderlichen Felder zum Auffüllen von list_row.xml wie Menüname, Beschreibung, Preis und Bild enthalten. Ich konnte keine Möglichkeit finden, die listView von fragment.xml mit den list_row-Elementen zu füllen. Jede Hilfe oder Idee wäre dankbar.

PS: Ich denke in fragment.xml stattandroid:id="@+id/listView1" Feld muss ich schreibenandroid:id="@id/list" da ich ListFragment verwende

Antworten auf die Frage(1)

Ihre Antwort auf die Frage