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
上传中...
上传图片
插入图片