Android Question using KeyValueStore to build a map.

rleiman

Well-Known Member
Licensed User
Longtime User
Hi Everyone,

In my app I have this map:

B4X:
    Photos.Initialize
    Photos.Put("1", LoadBitmapSample(File.DirAssets, "IMG_0320.jpg", 50dip, 50dip))
    Photos.Put("The Jamarat", LoadBitmapSample(File.DirAssets, "IMG_0367.jpg", 50dip, 50dip))
    Photos.Put("Makka - Roof of Masjid", LoadBitmapSample(File.DirAssets, "IMG_0270.jpg", 50dip, 50dip))
    Photos.Put("Uhud - Masjid", LoadBitmapSample(File.DirAssets, "IMG_0327.jpg", 50dip, 50dip))
    Photos.Put("Masjid Kuba", LoadBitmapSample(File.DirAssets, "IMG_0325.jpg", 50dip, 50dip))
    Photos.Put("Uhud - Graves", LoadBitmapSample(File.DirAssets, "IMG_0328.jpg", 50dip, 50dip))
    Photos.Put("Kabba - The black stone", LoadBitmapSample(File.DirAssets, "IMG_0278.jpg", 50dip, 50dip))
    Photos.Put("Maqam-e-Ibrahim", LoadBitmapSample(File.DirAssets, "IMG_0272.jpg", 50dip, 50dip))
    Photos.Put("Bus to Makka", LoadBitmapSample(File.DirAssets, "IMG_0221.jpg", 50dip, 50dip))
    Photos.Put("Hajj terminal", LoadBitmapSample(File.DirAssets, "IMG_0375.jpg", 50dip, 50dip))
    Photos.Put("Muzdalifah - Salat", LoadBitmapSample(File.DirAssets, "IMG_0361.jpg", 50dip, 50dip))
    Photos.Put("Mina - Transportation", LoadBitmapSample(File.DirAssets, "IMG_0357.jpg", 50dip, 50dip))
    Photos.Put("Mina - Tents", LoadBitmapSample(File.DirAssets, "IMG_0350.jpg", 50dip, 50dip))
    Photos.Put("Mina - Where we sleep", LoadBitmapSample(File.DirAssets, "IMG_0349.jpg", 50dip, 50dip))
    Photos.Put("Changing of the Quibla", LoadBitmapSample(File.DirAssets, "IMG_0337.jpg", 50dip, 50dip))
    Photos.Put("Masjid Kuba 1", LoadBitmapSample(File.DirAssets, "IMG_0335.jpg", 50dip, 50dip))
    Photos.Put("Uhud - Quran revealed", LoadBitmapSample(File.DirAssets, "IMG_0329.jpg", 50dip, 50dip))
    Photos.Put("Kaba - Day time", LoadBitmapSample(File.DirAssets, "IMG_0273.jpg", 50dip, 50dip))
    Photos.Put("Kaba - Night time", LoadBitmapSample(File.DirAssets, "IMG_0261.jpg", 50dip, 50dip))
    Photos.Put("Madina - Day time", LoadBitmapSample(File.DirAssets, "IMG_0308.jpg", 50dip, 50dip))
    Photos.Put("Arafat - About to climb", LoadBitmapSample(File.DirAssets, "IMG_0251.jpg", 50dip, 50dip))
    Photos.Put("Madina - Inside", LoadBitmapSample(File.DirAssets, "IMG_0310.jpg", 50dip, 50dip))
    Photos.Put("Masjid Kuba 2", LoadBitmapSample(File.DirAssets, "IMG_0324.jpg", 50dip, 50dip))
    Photos.Put("Arafat - At the top", LoadBitmapSample(File.DirAssets, "IMG_0254.jpg", 50dip, 50dip))
    Photos.Put("Muzdalifah - Night time", LoadBitmapSample(File.DirAssets, "IMG_0362.jpg", 50dip, 50dip))
    Photos.Put("Makka - Duah", LoadBitmapSample(File.DirAssets, "IMG_0285.jpg", 50dip, 50dip))
    Photos.Put("Madina - Roof of Masjid", LoadBitmapSample(File.DirAssets, "IMG_0312.jpg", 50dip, 50dip))

I'm using the UltimateListView to reorder this values in this map. In the ULV_Dropped sub routine I would like to be able to store the reordered list on the Android device using the KeyValueStore and later get the reordered list back into the UltimateListView. This will happen when the user starts the app up again after pressing the home button to quit from the app.

Can you tell me how I would go about doing that in my code?
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
- You have the map "Photos" (which is unordered)
- You fill a ULV with them and then you reorder the ULV

So

you should be able to rebuild a new map (ordered) when you iterate thru all ULV-Items in his actual order...

create new map for ordered Items.
Dim orderedmap AS Map
inizialize it...

start
- get item from ULV.
>Search the corresponding item in the Photos-Map and copy this item from Photos to orderedmap
back to start to get next item until you have reached the end of the ULV

Now you should have an ordered Map (orderedmap) which contains all your items in ordered form.
write this Map using keyvaluestore. And load it from kvs after appstart
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
Hi Everyone,

In my app I have this map:

B4X:
    Photos.Initialize
    Photos.Put("1", LoadBitmapSample(File.DirAssets, "IMG_0320.jpg", 50dip, 50dip))
    Photos.Put("The Jamarat", LoadBitmapSample(File.DirAssets, "IMG_0367.jpg", 50dip, 50dip))
    Photos.Put("Makka - Roof of Masjid", LoadBitmapSample(File.DirAssets, "IMG_0270.jpg", 50dip, 50dip))
    Photos.Put("Uhud - Masjid", LoadBitmapSample(File.DirAssets, "IMG_0327.jpg", 50dip, 50dip))
    Photos.Put("Masjid Kuba", LoadBitmapSample(File.DirAssets, "IMG_0325.jpg", 50dip, 50dip))
    Photos.Put("Uhud - Graves", LoadBitmapSample(File.DirAssets, "IMG_0328.jpg", 50dip, 50dip))
    Photos.Put("Kabba - The black stone", LoadBitmapSample(File.DirAssets, "IMG_0278.jpg", 50dip, 50dip))
    Photos.Put("Maqam-e-Ibrahim", LoadBitmapSample(File.DirAssets, "IMG_0272.jpg", 50dip, 50dip))
    Photos.Put("Bus to Makka", LoadBitmapSample(File.DirAssets, "IMG_0221.jpg", 50dip, 50dip))
    Photos.Put("Hajj terminal", LoadBitmapSample(File.DirAssets, "IMG_0375.jpg", 50dip, 50dip))
    Photos.Put("Muzdalifah - Salat", LoadBitmapSample(File.DirAssets, "IMG_0361.jpg", 50dip, 50dip))
    Photos.Put("Mina - Transportation", LoadBitmapSample(File.DirAssets, "IMG_0357.jpg", 50dip, 50dip))
    Photos.Put("Mina - Tents", LoadBitmapSample(File.DirAssets, "IMG_0350.jpg", 50dip, 50dip))
    Photos.Put("Mina - Where we sleep", LoadBitmapSample(File.DirAssets, "IMG_0349.jpg", 50dip, 50dip))
    Photos.Put("Changing of the Quibla", LoadBitmapSample(File.DirAssets, "IMG_0337.jpg", 50dip, 50dip))
    Photos.Put("Masjid Kuba 1", LoadBitmapSample(File.DirAssets, "IMG_0335.jpg", 50dip, 50dip))
    Photos.Put("Uhud - Quran revealed", LoadBitmapSample(File.DirAssets, "IMG_0329.jpg", 50dip, 50dip))
    Photos.Put("Kaba - Day time", LoadBitmapSample(File.DirAssets, "IMG_0273.jpg", 50dip, 50dip))
    Photos.Put("Kaba - Night time", LoadBitmapSample(File.DirAssets, "IMG_0261.jpg", 50dip, 50dip))
    Photos.Put("Madina - Day time", LoadBitmapSample(File.DirAssets, "IMG_0308.jpg", 50dip, 50dip))
    Photos.Put("Arafat - About to climb", LoadBitmapSample(File.DirAssets, "IMG_0251.jpg", 50dip, 50dip))
    Photos.Put("Madina - Inside", LoadBitmapSample(File.DirAssets, "IMG_0310.jpg", 50dip, 50dip))
    Photos.Put("Masjid Kuba 2", LoadBitmapSample(File.DirAssets, "IMG_0324.jpg", 50dip, 50dip))
    Photos.Put("Arafat - At the top", LoadBitmapSample(File.DirAssets, "IMG_0254.jpg", 50dip, 50dip))
    Photos.Put("Muzdalifah - Night time", LoadBitmapSample(File.DirAssets, "IMG_0362.jpg", 50dip, 50dip))
    Photos.Put("Makka - Duah", LoadBitmapSample(File.DirAssets, "IMG_0285.jpg", 50dip, 50dip))
    Photos.Put("Madina - Roof of Masjid", LoadBitmapSample(File.DirAssets, "IMG_0312.jpg", 50dip, 50dip))

I'm using the UltimateListView to reorder this values in this map. In the ULV_Dropped sub routine I would like to be able to store the reordered list on the Android device using the KeyValueStore and later get the reordered list back into the UltimateListView. This will happen when the user starts the app up again after pressing the home button to quit from the app.

Can you tell me how I would go about doing that in my code?
Just a comment about your code: you're defeating two advantages of ULV by loading all your images in advance. 1) You use a lot of memory. 2) Your loading takes time. It is better to store in your map the path to the image file and to use this path in the Filler event to load the image (synchronously with LoadBitmapSample if the image is small and you want to display it quickly, or asynchronously with LoadImageAsync in the other cases).
 
Upvote 0
Top