java - Adapter constructor of own implementation is not accepting hashMap.values() -


i implemented own adapter arrayadapter<>. within constructor using hashmap gets uuid key , random class called room. basically, smarthome app has rooms carry devices (fyi). however, implementation of constructor roomadapter (found @ https://github.com/codepath/android_guides/wiki/using-an-arrayadapter-with-listview) using super() - method not take hashmaps.

code

public roomadapter(context context, hashmap<uuid, room> room) {     super(context, r.layout.list_item_room, room.values()); } 

i @ beginners stage java, don't know have for. tried converting collection received when call room.values() arraylist used before tried use hashmap.

is there decent way fix problem @ position in code or have change code , use arraylist room?

the reason hashmap#values() not return arraylist. returns collection<t> object contains of values in map. arraylist<t> collection<t>, collection<t> not arraylist<t> adapter not know collection. arraylist, hashset, vector, linkedblockingqueue or of number of objects extend collection. may in fact custom implementation hashmap knows about. point doesn't matter underlying collection is, , hashmap doesn't make guarantees on return, that's interface you're stuck with.

you can fix code copying values in arraylist so:

super(context, r.layout.list_item_room, new arraylist(room.values())); 

however, because hashmap there no guarantee order in put items same order receive them.
values in whatever arbitrary order hashmap decides put them in.

a more predictable hashmap implementation linkedhashmap may serve purposes.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo