Java Android Studio自定义ArrayAdapter传递HashMap而不是ArrayList
我有一个自定义适配器,我想传递一个HashMap,其中Foo是一个自定义对象Java Android Studio自定义ArrayAdapter传递HashMap而不是ArrayList,java,android-studio,android-arrayadapter,Java,Android Studio,Android Arrayadapter,我有一个自定义适配器,我想传递一个HashMap,其中Foo是一个自定义对象 HashMap<String, Foo> foos = new HashMap<String, Foo>(); //populate foos and pass to adapter fooAdapter = new FooAdapter(getContext(), foos); HashMap foos=newhashmap(); //填充foos并传递给适配器 fooAdapter=new
HashMap<String, Foo> foos = new HashMap<String, Foo>();
//populate foos and pass to adapter
fooAdapter = new FooAdapter(getContext(), foos);
HashMap foos=newhashmap();
//填充foos并传递给适配器
fooAdapter=newfooadapter(getContext(),foos);
我的适配器看起来像这样
public class FooAdapter extends ArrayAdapter<Foo> {
public FooAdapter(Context context, HashMap<String, Foo> foos) {
super(context, R.layout.my_layout, foos);
}
公共类FooAdapter扩展了ArrayAdapter{
公共FooAdapter(上下文上下文,HashMap foos){
super(上下文,R.layout.my_layout,foos);
}
我的问题是如何将foos传递给基构造函数。如何使它接受HashMap而不是ArrayList。如果我将其作为ArrayList传递,效果会很好,但HashMap对我的应用程序会更好,因为我使用的是Firebase,并且在运行时需要密钥。使用
ArrayList
,这是不可能的
这是因为没有ArrayAdapter
的构造函数接受HashMap
。如果您在第105行看到,您将看到它在内部使用列表来存储其项
如果您想使用HashMap
而不是List
,只需通过扩展BaseAdapter
创建您自己的HashMapAdapter
,类似于源代码中显示的BaseAdapter
,只需将List
替换为HashMap
,并在整个代码中相应地更新此更改。@ScaryWombat nope do似乎不一样