开发者

associate custom ID to ListView items

开发者 https://www.devze.com 2023-01-13 07:28 出处:网络
Is it possible to use a hashmap in ArrayAdapter instanciation ? my \"regions\" hashmap handles custom ID as keys : Hashmap<ID,Value>.

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.simp开发者_Python百科le_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?


I would extend ArrayAdapter and add the logic there.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消