I am curious about converting the object type data into a list on Android

Asked 2 years ago, Updated 2 years ago, 170 views

I get the value from Google Firebase database to getvalue. When I saved it as a set value, the data that was listed was saved as an object type I'm calling it getValue, but I have to change the object data back to List type, but I can't do that ㅜ<

I'd like to extract two Double data and String data from the Object-in-type. I can't do that, so I'm thinking about it. Please....

This is the class you want to save

///////////////////////

package com.eum.ssrgo;

import com.google.firebase.database.IgnoreExtraProperties;

/**

Created by KHR on 2016-10-19. */ @IgnoreExtraProperties public class GetRidingList {

public Double latitude; public Double longitude; public String time;

public Double getlatitude(){ return latitude; }

public Double getlongitude(){ return longitude; }

public String gettime(){ return time; }

public GetRidingList(Double latitude, Double longitude) { this.latitude = latitude; this.longitude = longitude;

}

public GetRidingList(Double latitude, Double longitude, String time) { this.latitude = latitude; this.longitude = longitude; this.time = time; }

} ////////////////////////////////////

I'm writing again because I don't know how to write in main activity. Please

object android list conversion

2022-09-22 20:23

1 Answers

If you are using a firebase, you can import the list using the following functions: Please refer to the attached usage example below.

public T getValue (GenericTypeIndicator<T> t)

Assuming that the model class is defined as follows,

class Message {
    private String author;
    private String text;

    private Message() {}

    public Message(String author, String text) {
        this.author = author;
        this.text = text;
    }

    public String getAuthor() {
        return author;
    }

    public String getText() {
        return text;
    }
}

You can import them in the following ways:

GenericTypeIndicator<List<Message>> t = new GenericTypeIndicator<List<Message>>() {};
List<Message> messages = snapshot.getValue(t);


2022-09-22 20:23

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.