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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:30:01+00:00 2026-06-16T22:30:01+00:00

I have a list view with place distances, as shown below: 100 200 300

  • 0

I have a list view with place distances, as shown below:

100
200
300
400
500
50
600
70
40

i need to sort this place distances in both ascending and descending order. So wat i did was, sorting the adapter and use adapter.notifyDataSetChanged(). Everything works fine if the distances are 3 digit numbers ie., 230, 450, 352, 254 and so on. But if the place distance is 2 digit like 52, 65, 75 etc, i am getting wrong sorted values as shown below.

for ascending order : after sort i am getting this order

100
200
300
400
500
600
50
60
70

for descending order : after sort i am getting this order

70
60
50
600
500
400
300
200
100

my code for sorting is shown below:

case R.id.action_sort_dist_fn:

            adapter.sort(new Comparator<Place>() {

                @Override
                public int compare(Place lhs, Place rhs) {
                    return rhs.getPlaceDistance().compareTo(
                            lhs.getPlaceDistance());
                };
            });

            adapter.notifyDataSetChanged();
            break;

        case R.id.action_sort_dist_nf:

            adapter.sort(new Comparator<Place>() {

                @Override
                public int compare(Place lhs, Place rhs) {
                    return lhs.getPlaceDistance().compareTo(
                            rhs.getPlaceDistance());
                };
            });

Place.java

public class Place {
    String placeName = "";
            String placeDistance="";
            String placeCategoryIcon;

    public Place(String placeName, String placeDistance,
            String placeCategoryIcon) {

        this.placeName = placeName;
        this.placeDistance = placeDistance;
        this.placeCategoryIcon = placeCategoryIcon;
    }

    public String getPlaceName() {
        return placeName;
    }

    public void setPlaceName(String placeName) {
        this.placeName = placeName;
    }

    public String getPlaceDistance() {
        return placeDistance;
    }

    public void setPlaceDistance(String placeDistance) {
        this.placeDistance = placeDistance;
    }

    public String getPlaceCategoryIcon() {
        return placeCategoryIcon;
    }

    public void setPlaceCategoryIcon(String placeCategoryIcon) {
        this.placeCategoryIcon = placeCategoryIcon;
    }

}
  • 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-16T22:30:02+00:00Added an answer on June 16, 2026 at 10:30 pm

    First of all the sorting you give is not the actual one you are getting. E.g the second one is actually:

    70
    600
    60
    500
    50
    400
    300
    200
    100
    

    The comparison shouldn’t be done using strings – it compares lexicographically, which means that the comparison is as described here. So “abc” is greater than “ab” and “d” is greater than “ccc”.

    You want to compare the number values, so please do so. One option is to use Integer.valueOf to get the actual integer value equivalents of the values you use.

    By the way I see no gain for you to have placeDistance a String field. Why don’t you have it as Integer all along?

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

Sidebar

Related Questions

In my app i have a list view, in that i need to place
I need to display a list of comments within a view. I have created
Is it possible to place my list view UNDER my scrollview. I have a
I have list view and its adapter stored as global variables. I am not
In my application, I have list view. Selecting another item in it, triggers an
I have a list view binded to a data source. How can I enable
I have a list view with 10 columns and I want each row to
I have a list view which is bound to a DataTable source. The sorting
I have a list view comprised of the following: // Add column headers for
I have a list view with many rows and have it set so that

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.