如何循环的ArrayList< HashMap的<字符串,字符串>>?字符串、LT、ArrayList、GT

2023-09-04 23:03:31 作者:风雨兼程

我有一个这样的ArrayList对象:

I have an ArrayList object like this:

ArrayList<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();

如何通过列表循环? 我想显示在一个TextView其中来自ArrayList对象的数据的价值。

How to iterate through the list? I want to display the value in a TextView which comes from the data of ArrayList object.

推荐答案

简单的方法是遍历所有的的HashMap S在该的ArrayList ,然后遍历所有键地图

Simplest is to iterate over all the HashMaps in the ArrayList and then iterate over all the keys in the Map:

TextView view = (TextView) view.findViewById(R.id.view);

for (HashMap<String, String> map : data)
     for (Entry<String, String> entry : map.entrySet())
         view.append(entry.getKey() + " => " + entry.getValue());
 
精彩推荐
图片推荐