首页 > 解决方案 > 如何通过索引获取 Firebase 的值?

问题描述

我正在尝试根据位置从 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);

是否有另一种方法可以访问此列表中的第一个位置?我的数据库如下所示:

虽然我不知道,第一个键是 1,第二个是 2,依此类推

标签: javaandroidfirebasefirebase-realtime-database

解决方案


推荐阅读