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

  • Home
  • SEARCH
  • 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 8020947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:49:55+00:00 2026-06-04T21:49:55+00:00

I have an arrayList listItems with multiple objects, each having an Item Name and

  • 0

I have an arrayList “listItems” with multiple objects, each having an “Item Name” and “Item Price”.

I create a custom base adapter “adapterItems” and in my activity I set the adapter to the list

AdapterItems adapterItems = new AdapterItems(MyActivity.this, listItems);
listView.setAdapter(adapterItems);

Everything works fine and all the items are displated in my activity as a list view in the order the objects were added to the arrayList.

Now I want to sort this list by ascending order of item price.

I am ok to sort the listItems first before giving it to the adapter OR sort the listview adapter later on. How can I do either/both?

  • 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-04T21:49:58+00:00Added an answer on June 4, 2026 at 9:49 pm

    Use Comparable to sort your listview.

    See this Example That compare name and sort it in Alphabetical order

    in your case::

    public class Item implements Comparable<Item> {
    
        public String name;
        public int price;
    
        public int compareTo(Item another) {
            return (this.price-another.price);
        }
    }
    

    And

    Collections.sort(yourlist);

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

Sidebar

Related Questions

At the moment inside the class I have ArrayList which the objects are stored
I have an ArrayList that I want to use to hold RaceCar objects that
i have a listView with a custom BaseAdapter.Every list item has a clickable button.
I have an ArrayList of an object which has properties Object.name and Object.url .
I have Custom List to display image with it's name like below... public class
I have a custom list adapter contains a layout with controls in it. I
I have arraylist myorderdata . I want to retrieve this arraylist to one String
I have an arraylist that gets different type of values in it, 1st value->
I have an arraylist which has a class datastructure. public class empRec { public
I have an arraylist set up. I have input instuctions set up too, so

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.