B4J Question How to filter objects ?

FrenchDeveloper

Member
Licensed User
Longtime User
Hello,
I have a set of objects. Each object is an imageview + properties.
This set will grow without limit.
What is the best solution to filter these objects upon one property ?

For example :

Object1 Imageview1 Group1
Object2 Imageview2 Group1
Object3 Imageview3 Group1
Object4 Imageview4 Group2
Object5 Imageview5 Group2

I need to do something on all imageviews of group2.
I could scan each object with a For Each loop but it may be quite long with a lot of objects.
I could copy all properties in a database, a table or in a map and filter the database, the table or the map. Is it possible to filter a table or a map ?
What is the most efficient solution ?
 

Attachments

  • Map filter.zip
    104.1 KB · Views: 243
Last edited:

stevel05

Expert
Licensed User
Longtime User
You could keep an index (as a Map) of the objects that contain each group keyed on the group with a list of objects as the Value.
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
You could store the info you want using setUserData in each Imageview, then retrieve it with getUserData. It takes a java object so you could store almost anything in there.
You would probably need to use RunMethod to access the field as I don't think B4J exposes it.
 
Upvote 0

FrenchDeveloper

Member
Licensed User
Longtime User
You could keep an index (as a Map) of the objects that contain each group keyed on the group with a list of objects as the Value.
Thank you for your answer!
As I am a newbie, I don't imagine how the code would be and how to filter a map upon this index. May be you know a thread where I can find example ?
 
Upvote 0

FrenchDeveloper

Member
Licensed User
Longtime User
Thanks for this advice ! I didn't think it would be possible to store informations in java objects.
How to filter upon one of these informations ?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
If you can give me an example of how you are coding the structure, I'll give you an example of indexing it using Map.
 
Upvote 0

FrenchDeveloper

Member
Licensed User
Longtime User
If you can give me an example of how you are coding the structure, I'll give you an example of indexing it using Map.

Thank you very much Stevel ! I added a project in the first post.
May be you know where I can find further informations on maps purpose and coding ?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
No Problem, attached is an example.

You can get info on maps from the internet, there are many examlples. One is: http://www.javamex.com/tutorials/collections/using_4.shtml.

Although the examples will be in java, it should be easy to change for B4a/j. If you get any questions just post then in the forums and someone will help.

Steve
 

Attachments

  • MapFilter1.zip
    2.6 KB · Views: 230
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…