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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:54:00+00:00 2026-06-02T16:54:00+00:00

I implement a JSONArray to populate a ListView. Now I want to sort the

  • 0

I implement a JSONArray to populate a ListView. Now I want to sort the items on the ListActivity alphabetically by its name, which is its Object Attribute.
How am I able to sort it out?

Heres the Object class I use to implement the ListView:

public class VideoLocation {

    public String deleted_at = null;
    public int documentary_video_length = -1;
    public int id = -1;
    public double latitude = 0d;
    public double longitude = 0d;
    public int position = -1;
    public String updated_at = null;
    public String name = null;
    public String text = null;
    public String documentary_video_url = null;
    public String documentary_thumbnail_url = null;
    public String audio_text_url = null;
    public Footage[] footages = null;

    public VideoLocation(){

    }

and here’s the ListActivity Class:

    public class ProjectsList extends ListActivity implements OnItemClickListener, VideoLocationReceiver{
        /** Called when the activity is first created. */

        private VideoLocation[] videoLocations = null;
        private VideoLocationAdapter videoLocationAdapter = null;

        @Override
        public void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);
            setContentView(R.layout.projects_list);

            doSync();
            //storeSharedPrefs();
            ListView lv = getListView();
            lv.setOnItemClickListener(this);

            videoLocationAdapter = new VideoLocationAdapter(ProjectsList.this, 
                    R.layout.listitems, 
                    new VideoLocation[0]);
            lv.setAdapter(videoLocationAdapter);

            //CREATE VideoLocation[] from Database!

            JsonDB dbhelper = new JsonDB(ProjectsList.this);
            SQLiteDatabase db = dbhelper.getWritableDatabase();

            db.beginTransaction();
            videoLocations = dbhelper.getVideoLocations(db);
            db.setTransactionSuccessful();//end transaction
            db.endTransaction();
            db.close();
        }

        @Override
        public void onResume(){
            super.onResume();
            DBSync.setVideoLocationReceiver(ProjectsList.this);
        }

        @Override
        public void onPause(){
            super.onResume();
            DBSync.setVideoLocationReceiver(null);
        }

        @Override
        public void onItemClick(AdapterView<?> l, View v, int position, long id) {
            Intent listIntent = new Intent(this, ProjectDetailsActivity.class);

            VideoLocation vidLocation = videoLocations[position];
        listIntent.putExtra("documentary_video_url",vidLocation.documentary_video_url);
            startActivity(listIntent);

        }
protected void storeSharedPrefs() {
        final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        if (prefs.getBoolean("first-time", true)) {
            doSync();
            prefs.edit().putBoolean("first-time", false).commit(); // record the fact that the app has been started at least once
        }
    } 

    void doSync() {
        Intent serviceIntent = new Intent(this, DBSync.class);
        startService(serviceIntent);
    }

    public class VideoLocationAdapter extends ArrayAdapter<VideoLocation> {
        public ImageLoader imageLoader; 
        ImageLoader loader = null;

        public VideoLocationAdapter(Context context, int resource, VideoLocation[] vidLocs) {
            super(context, resource, vidLocs);
            ProjectsList.this.videoLocations = vidLocs;       
            loader = new ImageLoader(context);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {

            if(convertView == null){
                convertView = ProjectsList.this.getLayoutInflater().inflate(R.layout.listitems, null, true);
            }

            VideoLocation vidLocation = videoLocations[position];
            ImageView v = (ImageView)convertView.findViewById(R.id.image);
            String url = vidLocation.documentary_thumbnail_url;
            v.setTag(url);
            loader.DisplayImage(url, ProjectsList.this, v);
            TextView titleView = (TextView)convertView.findViewById(R.id.txt_title);
            titleView.setText(vidLocation.name);
            return convertView;
        }

        @Override
        public int getCount(){
            return videoLocations==null?0:videoLocations.length;
        }

        @Override
        public VideoLocation getItem(int position){
            return videoLocations[position];
        }

        @Override
        public boolean hasStableIds(){
            return true;
        }

        @Override
        public boolean isEnabled(int position){
            return true;
        }

        @Override
        public long getItemId(int position){
            return videoLocations[position].id;
        }

        public void setVideoLocationData(VideoLocation[] newData){
            ProjectsList.this.videoLocations = newData;
            VideoLocationAdapter.this.notifyDataSetChanged();
        }
    }

    @Override
    public void receivedVideoLocationData(VideoLocation[] vidLocs) {
        final VideoLocation[] locs = vidLocs;

        if (vidLocs==null) {
            runOnUiThread(new Runnable() {

                @Override
                public void run() {

                    //show popup and inform about missing network
                }
            });
        }else{
            runOnUiThread(new Runnable() {

                @Override
                public void run() {

                    videoLocationAdapter.setVideoLocationData(locs);
                    Log.d("ProjectsList", "updating video locations...");
                }
            });
        }
    }

}
  • 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-02T16:54:02+00:00Added an answer on June 2, 2026 at 4:54 pm

    Use Collections.sort. Parse your json and fill up a vector or an ArrayList (I think) with instance of VideoLocation. Then call Collections.sort.

    Edit:

    Collections.sort(youarrayList, new Comparator<VideoLocation>() {
    
                @Override
                public int compare(VideoLocation lhs, VideoLocation rhs) {
                    return lhs.name.compareTo(rhs.name);
                }
            });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have listView in which I inflate a row contain textview and button now
I want to implement on my site show-hidden div block as on stackoverflow.com -
I want to implement a REST-api in C#. I found that WCF Webapi can
I want to implement a chat application but I don't want to use timeout
I want to implement an AsyncTaskLoader in my project using the Compatibility Package, so
Question Implement a function bool chainable(vector<string> v) , which takes a set of strings
we implement in-app purchase, but want to receive some information about user: the user
I implement very big script logic using jquery plugin at caret(http://code.google.com/p/jquery-at-caret/), but now when
Which would be the best way to do it? Right now, I convert my
I implement some thing like this - person grid - name address action a

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.