程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> arraylist-將所有數組數據放入哈希圖

arraylist-將所有數組數據放入哈希圖

編輯:編程綜合問答
將所有數組數據放入哈希圖

有一個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);

最佳回答:


 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);
 }
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved