简体   繁体   English

Firebase 在 android 工作室中没有按字母顺序对文件进行排序,?

[英]Firebase not sorting files alphabetically in android studio,?

I am using firebase storage for saving images, when I retrieve them on application, files are not sorting alphabetically.我正在使用 firebase 存储来保存图像,当我在应用程序上检索它们时,文件没有按字母顺序排序。 Firebase sorting files by date time, first upload showing on first then second. Firebase 按日期时间排序文件,首先上传显示在第一位,然后显示在第二位。 I have a lot of files and cannot upload these files one by one.我有很多文件,无法一一上传。 Is there any way to sort files by alphabetically.有什么方法可以按字母顺序对文件进行排序。 like喜欢

001.png
002.png
003.png
004.png
005.png

……

` `

private void saveAllSigns() {
    showDialog();
    for (int i = 0; i < SignNameList.length; i++) {
        StorageReference storageReference = FirebaseStorage.getInstance().getReference().child(SignNameList[i]);
        int finalI1 = i;
        storageReference.listAll().addOnSuccessListener(new OnSuccessListener<ListResult>() {
            @Override
            public void onSuccess(ListResult listResult) {
                List<StorageReference> list = listResult.getItems();
                for (StorageReference str : list) {
                    long SIZE = 1024 * 1024;
                    str.getBytes(SIZE).addOnSuccessListener(new OnSuccessListener<byte[]>() {
                        @Override
                        public void onSuccess(byte[] bytes) {
                            saveData(bytes, str.getName(), finalI1);
                        }
                    }).addOnFailureListener(new OnFailureListener() {
                        @Override
                        public void onFailure(@NonNull Exception e) {
                            Log.d("SlashLog", "Firebase Exception: " + e.getMessage());

                        }

` `

looking for solution寻找解决方案

According to the Firebase documentation given by frank, listAll() call should be returning the files in lexicographical order.根据 frank 提供的 Firebase 文档, listAll()调用应该按字典顺序返回文件。

Seems order of the files in the list is being changed by the for loop that iterates through the list.似乎列表中文件的顺序正在被遍历列表的for循环更改。 Maybe you should try sorting the list before iterating through it.也许您应该在遍历列表之前尝试对列表进行排序。

listAll() method is being called inside a for loop that iterates over the SignNameList . listAll()方法在迭代SignNameListfor循环中被调用。 If the elements in the SignNameList array are in chronological order, then the listAll() method will return the files in chronological order as well.如果 SignNameList 数组中的元素按时间顺序排列,则listAll()方法也将按时间顺序返回文件。

As also mentioned here , Consistency of the result is not guaranteed if objects are inserted or removed while this operation is executing.也如此处所述,如果在执行操作时插入或删除对象,则无法保证结果的一致性。

thanks for answer but error has resolved from here in data base helper ORDER BY ASC感谢您的回答,但数据库助手 ORDER BY ASC 中的错误已从此处解决

        Cursor cursor = db.rawQuery("SELECT * FROM " + TABLE_SIGNS +" ORDER BY fileName ASC", null);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM