码迷,mamicode.com
首页 > 移动开发 > 详细

android 合并数组

时间:2015-09-05 22:19:37      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:

我有三个数组:
[code=java]final String[] names = mThemeResources.getStringArray(names);
final String[] infos = mThemeResources.getStringArray(info);
final String[] tos = mThemeResources.getStringArray(to);[/code]

如何把这三个数组保存成一个数组例如
{
names[0] infos[0] tos[0],
names[1] infos[1] tos[1],
names[2] infos[2] tos[2],
...........
}
并且显示在Listview上,listview上每个Item有三个Textview分别对应:names,infos,tos




1.

用List<Map<String,String>>,Map可以放三个

1
2
3
4
5
6
for(i=0;i<names.length;i++){
map.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<String> temp = new LinkedList<String>();//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左滑会出现一个删除按钮那样。

android 合并数组

标签:

原文地址:http://www.cnblogs.com/tonglingqijie/p/4783936.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!