gpt4 book ai didi

android - 如何将arraylist中的所有值放入android中的hashmap?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:58:29 25 4
gpt4 key购买 nike

我有一个 ArrayList,我想将所有数组数据放入我的 HashMap 中,但问题是我得到的只是数组列表的最后一个索引值。这是我的代码

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);

最佳答案

你必须把

     HashMap<String, String> map = new HashMap<String, String>();

在 for block 内

您只有一个“ map ”实例,并且您只是在更改该 map 的值。

关于android - 如何将arraylist中的所有值放入android中的hashmap?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17461366/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com