これは私のJavaのリストです。私に与えられリストに1つ以上の値を入れる方法は?
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" />
これは
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10px" >
</ListView>
あなたはnewscommentlist xmlファイルを投稿することができますnewscomments.xmlのですか? –
あなたのコメント、commentdate、commentposterの値が同じようです。同じ値を持つキーをHashMapに配置することはできません。 – digulino
毎回同じマップを追加しています –