How to Retrieve a List object from the firebase in android

后端 未结 5 1960
无人共我
无人共我 2020-11-30 03:13

I am having trouble retrieving a List from the Firebase. I have no trouble storing it, but as soon as I try to cast dataSnapshot.getValue() to ArrayList my app crashes, givi

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-30 03:54

    A bit late, but in case any one else needs this.

    IF the list is inside another object.

    The object

    public class Question {
    
        public Date date;
        public String questionNumber;
        public String questionText;
        public QuestionType questionType;
        public String multipleSelection1;
        public String multipleSelection2;
        public String multipleSelection3;
    
        public Question() {
            // Default constructor required for calls to DataSnapshot.getValue(User.class)
        }
    }
    

    Then to get your array of question objects

    GenericTypeIndicator> t = new GenericTypeIndicator>() {};
    List questionList = dataSnapshot.getValue(t);
    

提交回复
热议问题