android - 为什么 firebase 查询看起来不像列表?

标签 android firebase firebase-realtime-database

我正在根据日期查询 firebase。 我找到了我的查询,但它看起来不像 firebase。 这个顺序对我很重要。 另一张图片链接: firebase

 -LP6nkhewJCIGplnE6L4
adSoyad: 
"RUKIYE POLAT"
tarih: 
"18/10/2018,18:33:02"
-LP7EBqo6pabsweqH-4G
adSoyad: 
"RUKIYE POLAT"
tarih: 
"18/10/2018,20:32:56"
-LPBblB72HizL1LaJDIp
adSoyad: 
"RUKIYE POLAT"
tarih: 
"19/10/2018,16:58:45"
-LPCNo2DoDkArJJUQMCp
adSoyad: 
"RUKIYE POLAT"
tarih: 
"19/10/2018,20:33:01"
-LPF-MEziEXaoaNezNHQ
adSoyad: 
"RUKIYE POLAT"
tarih: 
"20/10/2018,8:45:03"
-LPGfoeIVNGq1MRmOEbY
adSoyad: 
"RUKIYE POLAT"
tarih: 
"20/10/2018,16:34:34"
-LPGfpCRniADm6sgGWyy
adSoyad: 
"RUKIYE POLAT"
tarih: 
"20/10/2018,16:34:34"
-LPK8Puua1kLv5eV7NOF
adSoyad: 
"RUKIYE POLAT"
tarih: 
"21/10/2018,8:42:44"
-LPLqoKyV_YiaMqKozxb
adSoyad: 
"RUKIYE POLAT"
tarih: 
"21/10/2018,16:40:42"
-LPLqosW54-5q8hUfNoK
adSoyad: 
"RUKIYE POLAT"
tarih: 
"21/10/2018,16:40:43"

sample, in Firebase Date: 20/10 / 2018,8: 32 there is another child under Date: 20/10 / 2018,16: 39

I also want to come like in this order. According to the time from the database ie in the order of the list as in the firebase.But Firstly,is coming

Date: 20/10 / 2018,16: 39
Date: 20/10 / 2018,8: 32 

但我想像上面列出的那样 第一
日期:20/10/2018,8:32 日期:20/10/2018,16:39 另一张图片链接:https://i.hizliresim.com/j691AL.jpg application

数据库中有很多数据,无法修复。

DatabaseReference dbGelenler = db.getReference(kimlik+"/"+cekilensifre+"/"+cekilenisim);

Query query = dbGelenler.orderByChild("tarih").startAt(birincitarih).endAt(birincitarih + "\uf8ff");
        query.addListenerForSingleValueEvent(new ValueEventListener() {
    public void onDataChange(DataSnapshot dataSnapshot) {

        List<String> isimler = new ArrayList<String>();
        for (DataSnapshot anahtar : dataSnapshot.getChildren()) {
            String isim = anahtar.getValue(ornekogrencigetir.class).getAdSoyad();
            String tarih = anahtar.getValue(ornekogrencigetir.class).getTarih();
            HashMap<String, String> user = new HashMap<>();

            if (isimler.indexOf(isim) == -1) {
                user.put("hashdurum", "Giriş");
                String[] seperated;
                seperated = tarih.split(",");
                user.put("hashtarih", seperated[0]);
                user.put("hashsaat", seperated[1]);
            } else {
                user.put("hashdurum", "Çıkış");
                String[] seperated1;
                seperated1 = tarih.split(",");
                user.put("hashtarih", seperated1[0]);
                user.put("hashsaat", seperated1[1]);
            }
            isimler.add(isim);
            veriler.add(user);

为什么不按顺序查询呢?我该如何解决这个问题?

Edit:Error Solved:

查询信息按时间排序。 有时在我的数据库中前面不包含 0。 这些是上午 12 点之后到上午 10 点的时间。 例如,上午 9 点。 所以比较firebase clock的时候,引用下一个。 情况举例 9:12:15 到 15:24:54 他这里比较的情况是91和15,所以先取15:24:54,然后取9:12:15。

最佳答案

您将日期/时间存储在数据库中的字符串值中,格式为 dd/MM/yyyy hh:mm:ss。 Firebase 中的字符串是按字典顺序排列的,不幸的是,在您使用的日期格式中,值的字典顺序和时间顺序是不同的。

解决方案是将日期/时间值存储为允许按您希望的方式排序的格式。两种最常见的方法是将它们存储为时间戳(一个数值,即自特定日期以来的毫秒数),或以可排序的字符串格式(通常为 2018-10-20T16:34:34).

有关此的更多信息,请参阅:

关于android - 为什么 firebase 查询看起来不像列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52921518/

相关文章:

firebase - 复杂的 Firebase 安全规则

java - boolean 值第一次在 Activity 中返回 false

javascript - 在 firebase 中同步运行函数

android - 如何获取 View 在坐标中的位置?

android - 如何使用 BroadcastReceiver 检测蓝牙状态

ios - Firebase:第二次调用 setUserID() 似乎不起作用

android - 将其与 Firebase 链接后 Flutter 卡住了

java - Android 折线图

java - 在 Android 中以编程方式更改 DNS

android - 地理编码器返回长度为零的地址