내가 본래 원했던 것은 firebase orderByChild를 통하여 recyclerView를 내림차순으로 정렬하는 거였다.
먼저 내가 시도했을 때 소용 없었던 방법을 소개하겠다.
1. 공식문서에 있는 내용
citiesRef.orderBy("name", Direction.DESCENDING);
이 방법은 공식문서에서 나온 내용이나 실제로 위와 같이 코드를 입력하면 작동이 안 된다.
Direction에서 문제가 생겨 통하지 않는다.

출처: https://firebase.google.com/docs/firestore/query-data/order-limit-data#java_2
Cloud Firestore로 데이터 정렬 및 제한 | Firebase Documentation
Join Firebase at Google I/O online May 11-12, 2022. Register now 의견 보내기 Cloud Firestore로 데이터 정렬 및 제한 Cloud Firestore는 컬렉션에서 검색할 문서를 지정하는 강력한 쿼리 기능을 제공합니다. 데이터 가
firebase.google.com
2. Collections.reverse(list)
두 번째로 시도한 방법은 list를 불러올 때 뒤집어서 불러오는 방법이다.
그러나 Collections.reverse(list)를 하면 안타깝게도 정렬이 중구난방이 되어버린다.
그래서 이 방법도 실패했다.

출처: https://stackoverflow.com/questions/57639937/sort-firebase-data-in-ascending-descending-order
Sort Firebase data in ascending/Descending Order
I'm Working with stock management project and my client want sales of stock in ascending and descending order. I have Stock structure as below I want to sort the data as per the sales of the prod...
stackoverflow.com
내가 내림차순 정렬에 성공한 방법은 다음과 같다.
바로 LayoutManager를 이용한 방법이다!
내가 쓴 코드는 다음과 같다.
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
linearLayoutManager.setReverseLayout(true);
linearLayoutManager.setStackFromEnd(true);
recyclerView.setLayoutManager(linearLayoutManager);
Fragment가 아닌 Activity에 쓸 경우 getActivity() 대신 this를 넣어주면 된다.
이 방법대로 하면 예쁘게 내림차순 정렬이 된다.

'안드로이드 노트' 카테고리의 다른 글
[안드로이드][프로젝트2] 내가 long 값을 날짜 형식으로 변환한 방법 (0) | 2022.04.30 |
---|---|
[안드로이드][프로젝트2] disabled ratingbar 만들기 + ratingbar 크기 줄이기 (0) | 2022.04.27 |
[안드로이드][프로젝트2]BottomNavigationView 색상 변경하는 법 (0) | 2022.04.10 |
[안드로이드][프로젝트2] ratingBar 별 색깔 바꾸기 (0) | 2022.04.09 |
[안드로이드][프로젝트2] 투명한 Activity 만드는 방법 (0) | 2022.04.09 |