Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6101291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:28:59+00:00 2026-05-23T13:28:59+00:00

I use a ListView with android.R.layout.simple_list_item_multiple_choice as list items. I want to sort the

  • 0

I use a ListView with android.R.layout.simple_list_item_multiple_choice as list items. I want to sort the list (and maybe group the list) that checked items are on top of the list. I looked at the Comparator but it only lets me sort the list by the entries name of the list.
How could that be done in a nice way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:28:59+00:00Added an answer on May 23, 2026 at 1:28 pm

    Its not true that a Comparator can only Compare Strings. You could just extend Comparator yourself and compare your Objects. So if Your Object is “smaller” return -1 and if it is “greater” return 1, if equal 0.
    I’m asuming you have a simple Object representing a row of your list, lets say ListItem.
    Then You write

    public class ListItemComparator extends Comparator{
        public int compare(ListItem1 l1, ListItem2 l2){
            if(l1.isChecked && l2.isChecked) return 0;
            if(l1.isChecked && !l2.isChecked) return 1;
            else return -1;
            //or any other comparation you like
        }
        public boolean equals(ListItem1 l1, ListItem2 l2){
            //return true if compare returns 0
            return l1.isChecked && l2.isChecked;
        }
    }
    

    You could then sort your List with

    Collections.sort(List<ListItem> items, Comparator comparator)
    

    function and fill them with your ListItems and an Instance of your Comparator.
    after that tell the Adapter that you changed his Content

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have learned that when using android:entries with a ListView , it uses android.R.layout.simple_list_item_1
I use ListView to show several items. My row.xml as below: <TextView android:text=text android:id=@+id/tvViewRow
i want to use the listview flicker"less" control found here Link directly in my
I want to use the GridView mode of a ListView to display a set
I have a listview with 200 items. I use a custom view for each
I want some of the goodies in a ListView, like being able to use
I try to set text of ListView in center of layout. I use LinearLayout
I'm trying to create a custom ListView layout similar to android.R.layout.simple_list_item_2. However, when I
I am starting out on Android and trying to make a custom ListView layout.
I have a ListView that is populated with 50 items. This is the xml

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.