views:

23

answers:

2

Is it possible to use a hashmap in ArrayAdapter instanciation ?

my "regions" hashmap handles custom ID as keys : Hashmap<ID,Value>.

vRegions.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, regions));

the problem here is that ArrayAdapter will call my hashmap's toString() which will print value and discard ID!

I want to be able to use that ID , is there any way to set it as simple_list_item_1's ID so i can retreive it later inside onclick event?

A: 

I would extend ArrayAdapter and add the logic there.

Macarse
hello, we're not obliged to use hashmap, maybe there's a cleaner way out there to associate IDs to items ?
youssef azari
Create a class with a custom to string?
Macarse
how ? i don't want to show IDs as item labels..
youssef azari
A: 

Solved this by passing a hashmap to my ArrayAdapter where keys are texts and values are the IDs. I use the pressed item position to get the text then i search my hashmap for the associated ID.

youssef azari