Khaled :
I'm facing a problem that I have a list of different object types and I'm fetching that list using AddClildEventLitener(), so the problem is to retrieve those objects I should give specific object to "getValue(SpecificObject.class)".
So, How can I achieve this step?
Example of realtime DB structure:
-List
-random id1(Object)
-title
-description
-random id2(Object)
-first name
-last name
-random id3(Object)
-title
-image
-random id4(Object)
-title
-description
-image
Frank van Puffelen :
I'm pretty sure I've answered this not too long ago, but I'll try again.
The getValue(SpecificObject.class)
method maps the properties from the DataSnapshot
to an instance of the SpecificObject
class.
If you have multiple different object types in your database, you will:
- Have a separate Java/Kotlin class for each object type.
- Need to include an indication of each object's class in the database.
- Read that indicator (typically a property) first, and then...
- Call
getValue(...)
with the correct class for that type.
Also see:
- How to retrieve correct subtype from firebase android getValue() for an example of the condition and call in step 3 and 4.
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=386147&siteId=1