Search code examples
androidandroid-fragmentsandroid-tabs

How to sort ListFragment and display both accednding and descending order in the same tab in tab layout in android?


I have a tabbed layout with 3 tabs. All tabs are loaded with List Fragments. I need to sort the List Fragment in both ascending and descending order. Display both within the same tab. When we click the tab, it should sort in ascending order. If the same tab is re-selected, it to sort in descending order and display the result.

Is it possible to nest List-Fragment within a tab ?


Solution

  • Yes, we can achieve this by using Collections.reverse(list)

        // Here we are using reverse() method
        // to reverse the element order of mylist
        Collections.reverse(mylist);