Saturday 15 June 2013

java - Using implementation of Map interface instead of List interface to store data in BaseAdapter -



java - Using implementation of Map interface instead of List interface to store data in BaseAdapter -

i want utilize 1 of implementations of map interface instead of implementing arraylist store info in baseadapter. i'm looking best way values map index. creating lists map when have index seem highly not efficient.

@override public object getitem(int position) { // todo auto-generated method stub list<map.entry<string, string>> list = new linkedlist<map.entry<string,string>>(this.countries.entryset()); homecoming list.get(position); }

any suggestion how in right way?

thanks in advanace.

for performance, need maintain arraylist values of map in adapter separately :

// map<string, string> countries; arraylist<string> countrylist = new arraylist<string>(countries.values());

you need update list every time map changes , phone call notifydatasetchanged()

this way, optimal o(1) performance (as should be) getitem() :

@override public object getitem(int position) { homecoming position < countrylist.size() ? countrylist(position) : null; }

and don't forget homecoming right value in getcount() :

@override public object getcount() { homecoming countrylist.size(); }

note, there no guarantee on how values of list (coming map) ordered, may want sort them well.

java android

No comments:

Post a Comment