如何通过索引获取Firebase的值?

时间:2018-09-24 16:07:04

标签: java android firebase firebase-realtime-database

我正在尝试根据位置从Firebase检索数据。如果我不知道,第一个值的键是什么样的,我如何访问第一个头寸的值?

    ticketCodes.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

            GenericTypeIndicator<List<String>> t = new GenericTypeIndicator<List<String>>() {};
            List<String> yourStringArray = dataSnapshot.getValue(t);


// Here I want to receive the value of the first index in firebase without knowing what the key is. 
//I am not able to. Though if I put "get(firstKey)" it gives me the value of the first index.

String value = yourStringArray.get(0);

还有另一种方法来访问此列表中的第一位置吗? 我的数据库如下所示:

though i don't know, that the first key is 1 and the second 2 and so on

0 个答案:

没有答案