2 yue1liang1chuan yue1liang1chuan 于 2013.08.28 14:07 提问

将所有值放到hashmap中

有一个arraylist。我要将所有数组值放到哈希表中,但是问题是我得到的结果是数组列表的最后一个指针值。代码:

ArrayList<String> imagesFileName = new ArrayList<String>();
public String[] filename;

public static final String FILE_NAME = "filename";
public static final String DESCRIPTION = "filename1";
public static final String UPLOADEDBY = "filename2";
public static final String DATE_UPLOAD = "filename3";
public static final String ACTION = "filename4";
public static final String ID = "1";
ArrayList<HashMap<String, String>> mylist;

   filename = new String[imagesFileName.size()];
     for (int i = 0; i < imagesFileName.size(); i++) {
         filename[i] = imagesFileName.get(i);
    }


         mylist = new ArrayList<HashMap<String, String>>();
         HashMap<String, String> map = new HashMap<String, String>();
         for (int i = 0; i < imagesFileName.size(); i++) {
            map.put(FILE_NAME, filename[i]);
            map.put(DESCRIPTION, "desc");
            map.put(UPLOADEDBY, "uploadby");
            map.put(DATE_UPLOAD, "date_upload");
            map.put(ACTION, "delete");
            map.put(ID, "1");
            mylist.add(map);
    }
     adapter = new CustomArrayAdapter(getApplicationContext(), mylist, R.layout.attribute_ireport_list, 
             new String[]{FILE_NAME, DESCRIPTION, UPLOADEDBY, DATE_UPLOAD, ACTION, ID},
             new int[]{R.id.tv_File, R.id.txt_Desc, R.id.tv_UploadedBy, R.id.tv_DateUploaded, R.id.tv_Action, R.id.txt_id}, true);

        lv_iReport.setAdapter(adapter);

1个回答

Jave_
Jave_   2013.08.28 14:27
已采纳
for (int i = 0; i < imagesFileName.size(); i++) {
        HashMap<String, String> map = new HashMap<String, String>();//放进来
        map.put(FILE_NAME, filename[i]);
        map.put(DESCRIPTION, "desc");
        map.put(UPLOADEDBY, "uploadby");
        map.put(DATE_UPLOAD, "date_upload");
        map.put(ACTION, "delete");
        map.put(ID, "1");
        mylist.add(map);
}
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
把一个HashMap的值全部取出来,放到两个数组中
先是从数据库中获取所有的值,返回一个HashMap类型的数据: private HashMap searchSql() { int columnsSize = cursor.getColumnCount(); HashMap map = new HashMap(); if (cursor != null) { while (cursor.moveToNext()) { S
将HashMap中value值存入List中
1、取出HashMap中的value值,存入list中 package com.xtli.controller.algorithm; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import jav
HashMap封装查询到的数据
在读取联系人时,hashmape 封装的是一个人的信息,电话,姓名。
HashMap的创建和值添加
//HashMap的创建和值添加      HashMap hashMap = new HashMap();         hashMap.put("appName", "IPAD APP");         hashMap.put("appVer", "2.0");         hashMap.put("cmd","CV_Services.GetIndustryN
HashMap取出全部的value
HashMap取出全部的value
HashMap集合中装入ArrayList集合
package com.arraylist; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.Set; public class HashMapIncludeA
hashMap分别获取所有key和value
一直记不住,这次必须得自己记录一下了,遇到就查,太浪费时间了....虽然真的很基础的问题.... 1、code实现: import java.util.*; public class Main { public static void main(String[] args){ // Scanner scanner=new Scanner(System.in);/
Java中获取HashMap中所有的Key的值,获取所有的value的值
首先,确定有一个初始化并赋值的HashMap,我定义其为hashMap
HashMap 将object 当做key传入
<br />package test; import java.util.*; // Key class class A{ public int a; public int b; A(int a, int b){ this.a = a; this.b = b; } public boolean equals(Object o){ A x = (A)o; if(x.a == this.a && x.b == this.b) return tru
hashmap 循环取出所有值 取出特定的值 两种方法
//第一种 Iterator menus = menu.iterator(); while(menus.hasNext()) { Map userMap = (Map) menus.next(); System.out.print(userMap.get("link") + "\t"); // System.out.print(u