how to sort card view in recycler view in androidIs there a way to run Python on Android?How to save an Android Activity state using save instance state?Close/hide the Android Soft KeyboardWhy is the Android emulator so slow? How can we speed up the Android emulator?“Debug certificate expired” error in Eclipse Android pluginsIs there a unique Android device ID?What is 'Context' on Android?Proper use cases for Android UserManager.isUserAGoat()?How to create RecyclerView with multiple view type?how to filter the recycler view card view and show that card on top that is as 1st cardView based on some boolean flag?

How to find multiple values on the same line in any permutation using Notepad++?

Would it be possible to have a GMO that produces chocolate?

Is there any method of inflicting the incapacitated condition and no other condition?

Why do all fields in a QFT transform like *irreducible* representations of some group?

Is there any music source code for sound chips?

How do I request a longer than normal leave of absence period for my wedding?

Is there any practical application for performing a double Fourier transform? ...or an inverse Fourier transform on a time-domain input?

What are some interesting features that are common cross-linguistically but don't exist in English?

Numbers Decrease while Letters Increase

Which note goes on which side of the stem?

How can I unambiguously ask for a new user's "Display Name"?

Thank God it's Friday, tomorrow is THE weekend. Why the definite article?

Was it ever possible to target a zone?

Sci fi film similar to Village of the Damned

Nothing like a good ol' game of ModTen

Non-visual Computers - thoughts?

Identify a problem where a potentially winning move draws because of the 50 move rule

Why were the crew so desperate to catch Truman and return him to Seahaven?

What is the difference between "Grippe" and "Männergrippe"?

If the first law of thermodynamics ensures conservation of energy, why does it allow systems to lose energy?

LeetCode: Group Anagrams C#

Pair trading - short / long the spread

Best clipless pedals for sore feet?

What is this symbol: semicircles facing each other?



how to sort card view in recycler view in android


Is there a way to run Python on Android?How to save an Android Activity state using save instance state?Close/hide the Android Soft KeyboardWhy is the Android emulator so slow? How can we speed up the Android emulator?“Debug certificate expired” error in Eclipse Android pluginsIs there a unique Android device ID?What is 'Context' on Android?Proper use cases for Android UserManager.isUserAGoat()?How to create RecyclerView with multiple view type?how to filter the recycler view card view and show that card on top that is as 1st cardView based on some boolean flag?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








-2















I have some API response as below:



 [ 

accountType: a,
accountId: 1,
accountStatus: active,
isDefault: false,
accountName: texas1
,
accountType: b,
accountId: 1,
accountStatus: active,
isDefault: false,
accountName: texas2
,
accountType: c,
accountId: 1,
accountStatus: active,
isDefault: true,
accountName: texas4
,
accountType: a,
accountId: 1,
accountStatus: active,
isDefault: false,
accountName: texas5
,
accountType: b,
accountId: 1,
accountStatus: active,
isDefault: false,
accountName: texas6
,

accountType: a,
accountId: 1,
accountStatus: active,
isDefault: false,
accountName: texas7
,
accountType: b,
accountId: 1,
accountStatus: active,
isDefault: false,
accountName: texas9
]


I want the isDefault true account to be shown as first cardview with accountType as c then account type sorting should be done like account type a and its all account list and the account type b and all its account list. over all my card should like this



  • account type c

  • below default card

  • then account type a

  • all cards

  • then account type b

  • all cards

I always want isDefault card to be on top irrespective of its account type then I want to sort cardView based on accountType as a,b,c etc.
I m displaying account type then cardView below in xml layout
How to achieve this on Bindview? any help is appreciated










share|improve this question
































    -2















    I have some API response as below:



     [ 

    accountType: a,
    accountId: 1,
    accountStatus: active,
    isDefault: false,
    accountName: texas1
    ,
    accountType: b,
    accountId: 1,
    accountStatus: active,
    isDefault: false,
    accountName: texas2
    ,
    accountType: c,
    accountId: 1,
    accountStatus: active,
    isDefault: true,
    accountName: texas4
    ,
    accountType: a,
    accountId: 1,
    accountStatus: active,
    isDefault: false,
    accountName: texas5
    ,
    accountType: b,
    accountId: 1,
    accountStatus: active,
    isDefault: false,
    accountName: texas6
    ,

    accountType: a,
    accountId: 1,
    accountStatus: active,
    isDefault: false,
    accountName: texas7
    ,
    accountType: b,
    accountId: 1,
    accountStatus: active,
    isDefault: false,
    accountName: texas9
    ]


    I want the isDefault true account to be shown as first cardview with accountType as c then account type sorting should be done like account type a and its all account list and the account type b and all its account list. over all my card should like this



    • account type c

    • below default card

    • then account type a

    • all cards

    • then account type b

    • all cards

    I always want isDefault card to be on top irrespective of its account type then I want to sort cardView based on accountType as a,b,c etc.
    I m displaying account type then cardView below in xml layout
    How to achieve this on Bindview? any help is appreciated










    share|improve this question




























      -2












      -2








      -2


      1






      I have some API response as below:



       [ 

      accountType: a,
      accountId: 1,
      accountStatus: active,
      isDefault: false,
      accountName: texas1
      ,
      accountType: b,
      accountId: 1,
      accountStatus: active,
      isDefault: false,
      accountName: texas2
      ,
      accountType: c,
      accountId: 1,
      accountStatus: active,
      isDefault: true,
      accountName: texas4
      ,
      accountType: a,
      accountId: 1,
      accountStatus: active,
      isDefault: false,
      accountName: texas5
      ,
      accountType: b,
      accountId: 1,
      accountStatus: active,
      isDefault: false,
      accountName: texas6
      ,

      accountType: a,
      accountId: 1,
      accountStatus: active,
      isDefault: false,
      accountName: texas7
      ,
      accountType: b,
      accountId: 1,
      accountStatus: active,
      isDefault: false,
      accountName: texas9
      ]


      I want the isDefault true account to be shown as first cardview with accountType as c then account type sorting should be done like account type a and its all account list and the account type b and all its account list. over all my card should like this



      • account type c

      • below default card

      • then account type a

      • all cards

      • then account type b

      • all cards

      I always want isDefault card to be on top irrespective of its account type then I want to sort cardView based on accountType as a,b,c etc.
      I m displaying account type then cardView below in xml layout
      How to achieve this on Bindview? any help is appreciated










      share|improve this question
















      I have some API response as below:



       [ 

      accountType: a,
      accountId: 1,
      accountStatus: active,
      isDefault: false,
      accountName: texas1
      ,
      accountType: b,
      accountId: 1,
      accountStatus: active,
      isDefault: false,
      accountName: texas2
      ,
      accountType: c,
      accountId: 1,
      accountStatus: active,
      isDefault: true,
      accountName: texas4
      ,
      accountType: a,
      accountId: 1,
      accountStatus: active,
      isDefault: false,
      accountName: texas5
      ,
      accountType: b,
      accountId: 1,
      accountStatus: active,
      isDefault: false,
      accountName: texas6
      ,

      accountType: a,
      accountId: 1,
      accountStatus: active,
      isDefault: false,
      accountName: texas7
      ,
      accountType: b,
      accountId: 1,
      accountStatus: active,
      isDefault: false,
      accountName: texas9
      ]


      I want the isDefault true account to be shown as first cardview with accountType as c then account type sorting should be done like account type a and its all account list and the account type b and all its account list. over all my card should like this



      • account type c

      • below default card

      • then account type a

      • all cards

      • then account type b

      • all cards

      I always want isDefault card to be on top irrespective of its account type then I want to sort cardView based on accountType as a,b,c etc.
      I m displaying account type then cardView below in xml layout
      How to achieve this on Bindview? any help is appreciated







      android android-recyclerview cardview






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 28 at 2:28









      Sabbir Ahmed

      3282 silver badges10 bronze badges




      3282 silver badges10 bronze badges










      asked Mar 27 at 17:29









      hemahema

      14 bronze badges




      14 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          0















          The RecyclerView will display elements in the exact order that you pass them to your adapter. What you need to do is to rearrange your elements in the order you want them to be in and then pass them to the adapter so that they can be shown. A simple example based on your input



          //This is just a data class for our API response
          class Account
          String accountType;
          int accountId;
          boolean accountStatus;
          boolean isDefault;
          String accountName;


          //Lets say that you have your API response in a list as such
          List<Account> accountList = new ArrayList<>();
          accountList.add(/*Response from API*/);

          //Now we create a sorted list based on your rules
          List<Account> sortedAccountList = new ArrayList<>();

          //First we need the isDefault account
          for (Account account : accountList)
          if (account.isDefault)
          sortedAccountList.add(account);
          accountList.remove(account);
          break;



          //Now we add all 'c' type accounts
          for (Account account : accountList)
          if (account.accountType.equals("c"))
          sortedAccountList.add(account);
          accountList.remove(account);



          //Do the same as above for the other account types. You can also apply more rules as per your needs.





          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55383280%2fhow-to-sort-card-view-in-recycler-view-in-android%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0















            The RecyclerView will display elements in the exact order that you pass them to your adapter. What you need to do is to rearrange your elements in the order you want them to be in and then pass them to the adapter so that they can be shown. A simple example based on your input



            //This is just a data class for our API response
            class Account
            String accountType;
            int accountId;
            boolean accountStatus;
            boolean isDefault;
            String accountName;


            //Lets say that you have your API response in a list as such
            List<Account> accountList = new ArrayList<>();
            accountList.add(/*Response from API*/);

            //Now we create a sorted list based on your rules
            List<Account> sortedAccountList = new ArrayList<>();

            //First we need the isDefault account
            for (Account account : accountList)
            if (account.isDefault)
            sortedAccountList.add(account);
            accountList.remove(account);
            break;



            //Now we add all 'c' type accounts
            for (Account account : accountList)
            if (account.accountType.equals("c"))
            sortedAccountList.add(account);
            accountList.remove(account);



            //Do the same as above for the other account types. You can also apply more rules as per your needs.





            share|improve this answer





























              0















              The RecyclerView will display elements in the exact order that you pass them to your adapter. What you need to do is to rearrange your elements in the order you want them to be in and then pass them to the adapter so that they can be shown. A simple example based on your input



              //This is just a data class for our API response
              class Account
              String accountType;
              int accountId;
              boolean accountStatus;
              boolean isDefault;
              String accountName;


              //Lets say that you have your API response in a list as such
              List<Account> accountList = new ArrayList<>();
              accountList.add(/*Response from API*/);

              //Now we create a sorted list based on your rules
              List<Account> sortedAccountList = new ArrayList<>();

              //First we need the isDefault account
              for (Account account : accountList)
              if (account.isDefault)
              sortedAccountList.add(account);
              accountList.remove(account);
              break;



              //Now we add all 'c' type accounts
              for (Account account : accountList)
              if (account.accountType.equals("c"))
              sortedAccountList.add(account);
              accountList.remove(account);



              //Do the same as above for the other account types. You can also apply more rules as per your needs.





              share|improve this answer



























                0














                0










                0









                The RecyclerView will display elements in the exact order that you pass them to your adapter. What you need to do is to rearrange your elements in the order you want them to be in and then pass them to the adapter so that they can be shown. A simple example based on your input



                //This is just a data class for our API response
                class Account
                String accountType;
                int accountId;
                boolean accountStatus;
                boolean isDefault;
                String accountName;


                //Lets say that you have your API response in a list as such
                List<Account> accountList = new ArrayList<>();
                accountList.add(/*Response from API*/);

                //Now we create a sorted list based on your rules
                List<Account> sortedAccountList = new ArrayList<>();

                //First we need the isDefault account
                for (Account account : accountList)
                if (account.isDefault)
                sortedAccountList.add(account);
                accountList.remove(account);
                break;



                //Now we add all 'c' type accounts
                for (Account account : accountList)
                if (account.accountType.equals("c"))
                sortedAccountList.add(account);
                accountList.remove(account);



                //Do the same as above for the other account types. You can also apply more rules as per your needs.





                share|improve this answer













                The RecyclerView will display elements in the exact order that you pass them to your adapter. What you need to do is to rearrange your elements in the order you want them to be in and then pass them to the adapter so that they can be shown. A simple example based on your input



                //This is just a data class for our API response
                class Account
                String accountType;
                int accountId;
                boolean accountStatus;
                boolean isDefault;
                String accountName;


                //Lets say that you have your API response in a list as such
                List<Account> accountList = new ArrayList<>();
                accountList.add(/*Response from API*/);

                //Now we create a sorted list based on your rules
                List<Account> sortedAccountList = new ArrayList<>();

                //First we need the isDefault account
                for (Account account : accountList)
                if (account.isDefault)
                sortedAccountList.add(account);
                accountList.remove(account);
                break;



                //Now we add all 'c' type accounts
                for (Account account : accountList)
                if (account.accountType.equals("c"))
                sortedAccountList.add(account);
                accountList.remove(account);



                //Do the same as above for the other account types. You can also apply more rules as per your needs.






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 27 at 17:44









                Bilal NaeemBilal Naeem

                4521 silver badge8 bronze badges




                4521 silver badge8 bronze badges





















                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55383280%2fhow-to-sort-card-view-in-recycler-view-in-android%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

                    155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해