简体   繁体   English

如何设置ArrayList <HashMap<String,String> &gt;在ArrayAdapter中

[英]how to set an ArrayList<HashMap<String,String>> in an ArrayAdapter

Can we set an ArrayList containing HashMap into an ArrayAdapter ? 我们可以将包含HashMapArrayList设置为ArrayAdapter吗?

I'm using: 我正在使用:

ArrayList<HashMap<String,String>> items = new ArrayList<HashMap<String,String>>();
ArrayAdapter<ArrayList<HashMap<String, String>>> ad = new ArrayAdapter<ArrayList<HashMap<String,String>>>(this, android.R.layout.simple_list_item_1,items);

but this gives me an error saying: 但这给了我一个错误说:

The constructor ArrayAdapter>>(searchname, int, ArrayList>) is undefined 构造函数ArrayAdapter >>(searchname,int,ArrayList>)未定义

ArrayAdapter wants to know the type of the items inside the list, not the type of the list itself. ArrayAdapter想知道列表,该列表本身不是那种里面的物品的类型。 Remove the enclosing ArrayList<> and it should work. 删除封闭的ArrayList<> ,它应该工作。

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

ArrayAdapter<HashMap<String, String>> ad =
        new ArrayAdapter<HashMap<String,String>>(this,
            android.R.layout.simple_list_item_1,items);

have a look at this link Android Array Adapter with ArrayList and ListView not updating when the arraylist is changed . 看看这个链接Android Array Adapter与ArrayList和ListView在更改arraylist时不更新

basically you need to add your ArrayList into the ArrayAdapter through the add method. 基本上你需要通过add方法将ArrayList添加到ArrayAdapter中。

You can convert the type HashMap<String,String>> to a class. 您可以将类型HashMap<String,String>>转换为类。 For example, if the keys of the hashmap are countries and the values are lenguages, you can make a class called "Country" with this two variables (country,language). 例如,如果hashmap的键是国家,而值是lenguages,则可以使用这两个变量(国家/地区,语言)创建一个名为“Country”的类。 Then the AdapterClass have to extend the ArrayAdapter<Country> , in the getView method you can access both variables of each Country. 然后AdapterClass必须扩展ArrayAdapter<Country> ,在getView方法中,您可以访问每个Country的两个变量。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 ArrayList 为 Spinner 制作 ArrayAdapter <Hashmap<String, String> &gt;() - How to Make ArrayAdapter for Spinner with ArrayList<Hashmap<String, String>>() 设置ArrayList <HashMap<String,String> &gt;在ArrayAdapter中 - setting ArrayList<HashMap<String,String>> in a ArrayAdapter 如何设置ArrayList <HashMap<String, String> &gt;在AlertDialog中? - How to set ArrayList<HashMap<String, String>> in AlertDialog? 构造函数ArrayAdapter <ArrayList<HashMap<String, String> &gt;&gt;(Context,int,ArrayList <HashMap<String, String> &gt;)未定义 - The constructor ArrayAdapter<ArrayList<HashMap<String, String>>>(Context, int, ArrayList<HashMap<String, String>>) is undefined 如何将ArrayAdapter添加到ArrayList <ArrayList<String> &gt;()? - How to add a ArrayAdapter to a ArrayList<ArrayList<String>>()? 如何拆分字符串Arraylist Hashmap? - How to split string Arraylist Hashmap? 如何将HashMap存储在ArrayList中,然后存储到String [] - how to store HashMap in ArrayList then to String[] 如何存储一个ArrayList <HashMap<String, String> &gt;具有单个Hashmap和多个Arraylist - How to store an a ArrayList<HashMap<String, String>> with a single Hashmap and multiple Arraylist 为什么ArrayAdapter接受ArrayList <String> 但未设置 <String> 作为paramenter? - Why does ArrayAdapter accept ArrayList<String> but not Set<String> as paramenter? 如何为扩展 ArrayAdapter 的活动扩展 AppCompatActivity <hashmap<string, string> &gt;? </hashmap<string,> - How to extend AppCompatActivity for an activity which extends ArrayAdapter<HashMap<String, String>>?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM