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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:08:22+00:00 2026-06-09T21:08:22+00:00

I receive data from a server using JSON and I want to order them

  • 0

I receive data from a server using JSON and I want to order them alphabetically with alphabet indexed section and store them in a ListView.
Maybe something that will happen in :

for(int i=0;i<jArray.length();i++){
// here
}

I read that you can order elements like that only using a cursor. In my case would be very inefficient to store the elements from the server in the database and read them again. Waste of time and memory.

So, I am asking you if there could be any solution for my problem : order alphabetically with alphabet indexed section string received from JSON .

EDIT: I want my listview to look like this http://eshyu.wordpress.com/2010/08/15/cursoradapter-with-alphabet-indexed-section-headers/ . I mean with those sections . All tutorials I found said that you need to fetch information with a cursor. My question was if I could’t do this wihout a cursor, because it would be a waste of memory to store them in the local database too.

  • 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-09T21:08:23+00:00Added an answer on June 9, 2026 at 9:08 pm

    You may need to parse the JSON Array :

    List<Project> list = new ArrayList<Project>();
    
    for (int i = 0; i < jArray.length(); i++) {
        JSONObject obj = (JSONObject) jArray.get(i);
        project = new Project();
        project.setId( Long.parseLong(obj.get("id").toString()));
        project.setKey(obj.get("key").toString());
        project.setName(obj.get("name").toString());
    
        list.add(project);
    }
    

    You can use the comparator class like this to sort them :

    Collections.sort(list), new Comparator<Project>() {
        public int compare(Project p1, Project p2) {
            return p1.getKey().compareToIgnoreCase(p2.getKey());
        }
    });
    

    You can also have Project class and implements Comparable:

    public class Project implements Comparable<Project> {
       private long id;
       private String key;
       private String name;
    
       public int compareTo(Project p) {
        if (this.key > p.key)
            return -1;
        else if (this.key < p.key)
            return 1;
        return 0;
       }
    }
    

    And then sort the list by Collections.sort(list);

    My suggestion is try to sort the data in the Server-side, because the memory of the phone is limited and it may make you application time consuming to show the data, but you do not have memory limitation problem in the Server-side.

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

Sidebar

Related Questions

I am using json data received from server to display images. I am getting
I'm having difficulty parsing some JSON data returned from my server using jQuery.ajax() To
i am developing an iphone app that receive data from sql server through php
I have an app that received JSON data from the server. Currently when I
I have dynamic listview on my android client app that receive data from remote
i need to send and receive data to/from a microcontroller using java using usb
For my Visualization Table, i populated data from server side using PHP as guided
I am using NSURLConnection to download gzipped JSON from server. Is it possible to
I am using PHP + CURL to fetch data from a server in one
I receive an html encoded string from server code and I want to convert

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.