“Inhalte anzeigen mit id-Attribut " android.r.id.Liste", die nicht ein ListView-Klasse." beim erstellen einer Liste Ansicht in einem fragment

Hier ist das problem. Ich habe eine Liste anzeigen, und es sieht gut aus in dem Gebäude, aber es brach den Fehler.
Inhalte anzeigen mit id-Attribut " android.r.id.Liste", die nicht ein ListView-Klasse.

Habe ich nicht Hinzugefügt, das listview in der XML, so etwas wie :@android:Liste der Grund, warum ich nicht tun, ich könnte finden Sie einige Beispiele, die Sie nicht brauchen, um zu schaffen, wie der xml-Liste, also was soll ich jetzt tun?

Wie es zu lösen ist? danke!

Code für die Fragment.java

package com.example.demo3;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


import android.app.Activity;
import android.app.ListFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class ContactsFragment extends ListFragment {

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View contactLayout = inflater.inflate(R.layout.contacts_layout,
                container, false);
        return contactLayout;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        Activity currentActivity = getActivity();

        SimpleAdapter adapter = new SimpleAdapter(currentActivity, getData(),
                R.layout.contacts_layout,
                new String[] { "title", "info", "img" }, new int[] {
                        R.id.friend_name, R.id.friend_sex, R.id.friend_img });

        setListAdapter(adapter);

    }

    private List<Map<String, Object>> getData() {
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("title", "G1");
        map.put("info", "google 1");
        map.put("img", R.drawable.background_login);
        list.add(map);

        map = new HashMap<String, Object>();
        map.put("title", "G2");
        map.put("info", "google 2");
        map.put("img", R.drawable.background_login);
        list.add(map);

        map = new HashMap<String, Object>();
        map.put("title", "G3");
        map.put("info", "google 3");
        map.put("img", R.drawable.background_login);
        list.add(map);

        return list;
    }

    private TextView findViewById(int testmessage) {
        //TODO Auto-generated method stub
        return null;
    }

}

code für XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/friend_img"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5px" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/friend_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#000000"
            android:textSize="22px" />

        <TextView
            android:id="@+id/friend_sex"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#000000"
            android:textSize="13px" />
    </LinearLayout>

</LinearLayout>

aktualisiert:
Ich habe die

<ListView
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1" >
</ListView>

in der XML.
Obwohl das Bild/name/Geschlecht gezeigt hat, aber Sie sind nicht in der Liste erscheint die Liste ist ein separates element. Eine Idee, lassen Sie mich, um das Bild/name/Geschlecht in die Liste ein layout? THXXX!

  • Ohne Zugabe von ListView in eine XML -, wie es zu binden mit adapter?
  • Erstellen Sie layout-xml-Datei und fügen Sie Ihre ListView und deren id ist @android:id/list
  • Tatsächlich, ich bin neu in Android, also aus Ihrer Sicht, wo ist falsch in meinem Programm?
  • Eigentlich, wenn Sie möchten, verwenden Sie die Standard-layout für ListFragment dann ändern return contactLayout; zu return super.onCreateView(inflater, container, savedInstanceState); und fügen Sie benutzerdefinierte Ansicht zu container oder ohne fügen Sie einfach ListView-layout innen möchten Sie, dass Ihr layout für ListFragment
  • überprüfen Sie CommonsWare Antwort ein befolgen Sie die Schritte
Schreibe einen Kommentar