0

这是我的 Java 列表。

private void filldata() {
    ListView lv = (ListView) findViewById(android.R.id.list);

    String[] from = new String[] { comment, commentdate, commentposter };
    int[] to = new int[] { R.id.text_comment, R.id.text_commentdate,
            R.id.text_commentposter };
    List<HashMap<String, String>> fillMaps = new ArrayList<HashMap<String, String>>();
    for (int i = 0; i < 5; i++) {
        HashMap<String, String> map = new HashMap<String, String>();
        map.put(comment, "testing 1");
        map.put(commentdate, "testing 2");
        map.put(commentposter, "testing 3");
        fillMaps.add(map);
    }
    SimpleAdapter adapter = new SimpleAdapter(this, fillMaps,
            R.layout.newscommentlist, from, to);
    lv.setAdapter(adapter);
}

给我的输出是

测试 3

测试 3

测试 3

但我想要的是

测试 1

测试 2

测试 3

如何达到我的期望?

更新:

这是 newscommentlist.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="vertical"
android:background="#ffffff" >

<TextView
    android:id="@+id/text_commentdate"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginRight="10px"
    android:layout_marginTop="10px"
    android:gravity="right"
    android:textColor="#ff0000"
    android:textSize="20px" />

<TextView
    android:id="@+id/text_comment"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10px"
    android:layout_marginRight="10px"
    android:layout_marginTop="10px"
    android:gravity="fill_horizontal"
    android:textColor="#000000"
    android:textSize="30px" />

<TextView
    android:id="@+id/text_commentposter"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10px"
    android:layout_marginRight="10px"
    android:layout_marginTop="10px"
    android:gravity="right"
    android:textColor="#000000"
    android:textSize="35px" />

这是 newscomments.xml

<ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10px" >
    </ListView>
4

1 回答 1

0
private void filldata() {
    ListView lv = (ListView) findViewById(android.R.id.list);

    String[] from = new String[] { "comment", "commentdate", "commentposter" };
    int[] to = new int[] { R.id.text_comment, R.id.text_commentdate,
            R.id.text_commentposter };
    List<HashMap<String, String>> fillMaps = new ArrayList<HashMap<String, String>>();
    for (int i = 0; i < 5; i++) {
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("comment", "testing 1");
        map.put("commentdate", "testing 2");
        map.put("commentposter", "testing 3");
        fillMaps.add(map);
    }
    SimpleAdapter adapter = new SimpleAdapter(this, fillMaps,
            R.layout.newscommentlist, from, to);
    lv.setAdapter(adapter);
}
于 2012-04-26T11:17:55.867 回答