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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:29:15+00:00 2026-06-01T00:29:15+00:00

I have a listview connected to a custom array adapter. This list shows information

  • 0

I have a listview connected to a custom array adapter. This list shows information received by a TCP connection which changes the dataSet…

I am able to sort the listview with sort (Comparator<? super T> comparator), but when the dataSet is changed, the listview is no more sorted…

I can use sort () every time the dataSet is changed, but I think this is not the best option…

How can I do that? Any suggestions?

EDIT

I am having problems in implementing the solutions presented…

MyComparatorB.java

public class MyComparatorB implements Comparator<DeviceB> {

private byte orderType;

public MyComparatorB(byte type) {

    this.orderType = type;

}

public int compare(DeviceB lhs, DeviceB rhs) {

    int res = 0;
    if (orderType == SortType.ALPHA) {
            res = (lhs.getName()).compareTo(rhs.getName());
        }
        else if (orderType == SortType.LAST_ACT) {
            res = (rhs.getTime().getTime()).compareTo(lhs.getTime().getTime());
        }
        return res;
    }

}

Snippet of my customArrayAdapter.java

    @Override
public void notifyDataSetChanged() {
    super.notifyDataSetChanged();
}


//-----------Order the content of the arrayAdapter------------//
public void sort(byte sortType) {

    super.sort(new MyComparatorB(sortType));
    notifyDataSetChanged();
}

In my MyActivity.java

myDevAdapter.sort(SortType.ALPHA);

When I am debugging, the method super.sort(new MyComparatorB(sortType)); is called and the constructor of MyComparatorB is called too. But the method compare(DeviceB lhs, DeviceB rhs) is never called and my arrayList is not sorted…
What I am doing wrong?

  • 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-01T00:29:16+00:00Added an answer on June 1, 2026 at 12:29 am

    I guess you need to override notifyDataSetChanged method in your adapter and perform sorting right before calling its super. See below:

    @Override
    public void notifyDataSetChanged() {
        //do your sorting here
    
        super.notifyDataSetChanged();
    }
    

    Doing so will sort the list whenever you call notifyDataSetChanged method to refresh list items. Otherwise, feed a sorted List/array to your adapter.


    Or more preferably, use the sort method available in your adapter to get the job done.

    adapter.sort(new Comparator<String>() {
        @Override
        public int compare(String lhs, String rhs) {
            return lhs.compareTo(rhs);   //or whatever your sorting algorithm
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have ListView with custom Adapter which supplies View to ListView in this way:
In WPF app I have a ListView which is connected with ObservableCollection ShQuCollection through
I have an activity which have ListView. When I want to access this ListView
I have a ListView which sometimes I need to put around 10000 items in.
I have a ListView on a page that displays a list of widgets. When
I have a ListView (in an update panel) bound to an ObjectDataSource (connected to
In WPF app I have an Observable Collection which is connected through databinding with
I have listview with some listadapter after click on item from list I'd like
i have a custom list view. in that i am listing out images of
I have this following method that connectss to db and returns a json array.

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.