android 合并数组并且显示在Listview上

2025-02-26 21:00:52
推荐回答(2个)
回答1:

用List>,Map可以放三个

for(i=0;imap.put("name",names[i]);
map.put("info",infos[i]);
map.put("to",tos[i]);
list.add(map);
}

差不多这样,不在eclipse里写会有少许错误你自己调试一下

回答2:

第一个可以帮你实现,代码如下:
private static void test() {
String[] name = {"1", "2", "3"};
String info[] = {"a", "b", "c"};
String to[] = {"?", "?", "?"};
LinkedList temp = new LinkedList();//LinkedList链表结构插入快
for (int i = 0; i < name.length; i++) {
temp.add(name[i]);
}
for (int j = 0; j < info.length; j++) {
if (j == 0) {
temp.add(j + 1, info[j]);
} else {
temp.add(j * 2 + 1, info[j]);
}
}
for (int k = 0; k < to.length; k++) {
if (k == 0) {
temp.add(k + 2, to[k]);
} else {
temp.add(3 * k + 2, to[k]);
}
}
System.out.println(temp.toString());
}
第二个也不难,不过我没有试验过。ListView的item添加TextView感觉不可行,应该是跟Item并列的TextView,像手机QQ的对话item左滑会出现一个删除按钮那样。