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 8457959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:56:54+00:00 2026-06-10T12:56:54+00:00

I have a ListView that is populated by three (3) ArrayList ‘s: items ,

  • 0

I have a ListView that is populated by three (3) ArrayList‘s:

items, ratings and comments

However, I need to sort items by ignoring the leading ‘the’. I already have accomplished this by rearranging the items ArrayList using a Collections.sort (see code below), but this is the issue: the comments and ratings are not rearranged so it comes out of order in the ListView.

For example, if the list was:

  1. Cars 3 4
  2. People 5 3
  3. The Animals 7 4

After items sort I am getting:

  1. The Animals 3 4
  2. Cars 5 3
  3. People 7 4

So the items are lining up as I’d like but the associated comments and ratings aren’t sorted. I am not sure how to make that happen and where to place it. I think in the ArrayAdapter?

Here is the code I do to change the items list:

        Comparator<String> ignoreLeadingThe = new Comparator<String>() {
            public int compare(String a, String b) {
                a = a.replaceAll("(?i)^the\\s+", "");
                b = b.replaceAll("(?i)^the\\s+", "");
                return a.compareToIgnoreCase(b);
            }
        };

        Collections.sort(items, ignoreLeadingThe);

Here is the questions? Where and how can I sort the ratings and comments lists based on the position of the item list?

Edit:

this is my getView code in my ArrayAdapter:

    ItemObject io = getItem(position);
    String name = io.name;
    String total = io.total;
    String rating = io.ratings;
    String comment = io.comments;

    holder.t1.setText(name);
    holder.t2.setText(total);
    holder.t3.setText(comment);
    holder.t4.setText(rating);

Note: There is a 4th ArrayList called total I did not mention in the above example.

  • 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-06-10T12:56:56+00:00Added an answer on June 10, 2026 at 12:56 pm

    You should look at creating a class to wrap your items in the ArrayList, something like this:

    class MyItem {
        String item;
        int ratings;
        int comments;
    }
    

    Then have an ArrayList of these objects instead:

    List<MyItem> myList = new ArrayList<MyItem>();
    

    Then in your comparator, just do it like you’re doing, but testing against MyItem.item instead of just a and b. Something like this:

    Comparator<MyItem> ignoreLeadingThe = new Comparator<MyItem>() {
        public int compare(MyItem a, MyItem b) {
            a.item = a.item.replaceAll("(?i(^the\\s+", "");
            b.item = b.item.replaceAll("(?i(^the\\s+", "");
            return a.item.compareToIgnoreCase(b.item);
        }
    };
    
    Collections.sort(myList, ignoreLeadingThe);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListView that is populated using an XML file. However, I want
I have a ListView in a ListFragment that is populated via a database query.
I have a ListView that shows around 300 items. When something is changed and
I have a ListView that displays a link button. I need the link button
I have a listview that's populated by rows that get their data from a
I have a ListView that is populated with rows. These rows come from an
I have a ListView that is populated by a news server rundown (just a
I have a ListView in AcitivityA that is populated using a custom SimpleCursorAdapter called
I have a ListView that is being populated with a custom adapter. I have
I have a ListView that is being populated with a custom adapter. I'd like

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.