Android Question IterableList?

Misterbates

Active Member
Licensed User
Having just wrapped a Map and List into a MapList class/library, I was wondering how to implement Keys and Values methods to return an InterableList?

I'm guessing that I'll need to include some inline Java to expose an iterator and then respond to requests for the next item. Is this possible in B4A?

All advice gratefully received (especially if the advice is in the form of the inline Java to include) ;)
 

stevel05

Expert
Licensed User
Longtime User
That depends on your code, can't you just return the Keys and Values directly from the map?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
I've just seen you MapList, I assume this is for that. The List of keys is itself iterable in the sense that you can use a For Each on it.

If you want a Values list then you can create one on demand using the keys in the list and returning a new list containing the values from the map.

That then would also allow the For Each to be used and maintain the order of the keys list.

Or is there something else you want to do with it?

Edit: you may want to create a new list (copy) to return for the Keys so that it can't be changed.
 
Upvote 0

Misterbates

Active Member
Licensed User
I've just seen you MapList, I assume this is for that.
It is.
The List of keys is itself iterable in the sense that you can use a For Each on it. If you want a Values list then you can create one on demand using the keys in the list and returning a new list containing the values from the map. Edit: you may want to create a new list (copy) to return for the Keys so that it can't be changed.
So it's as simple as returning a list (copy) containing either keys or values in the same order as the internal Key List? I'll try that tomorrow.

Thanks!
 
Upvote 0
Top