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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:55:04+00:00 2026-05-14T06:55:04+00:00

I’m only starting with Android dev, and while the Milestone is a nice device

  • 0

I’m only starting with Android dev, and while the Milestone is a nice device Java is not my natural language and I’m struggling with both the Google docs on Android SDK, Eclipse and Java itself. Anyway…

I’m writing a microblog client for Android to go along with my Windows client (MahTweets). At the moment I’ve got Tweets coming and going without fail, the problem is with the UI.

The initial call will order items correctly (as in highest to lowest)

  • 3
  • 2
  • 1

When a refresh is made

  • 3
  • 2
  • 1
  • 6
  • 5
  • 4

After the tweets are processed, I’m calling adapter.notifyDataSetChanged();
Initially I thought that getItem() on the Adapter needed to be sorted (and the code below is what I ended up with), but I’m still not having any luck.

public class TweetAdapter extends BaseAdapter
{
private List<IStatusUpdate> elements;
private Context c;
public TweetAdapter(Context c, List<IStatusUpdate> Tweets)
{
    this.elements = Tweets;
    this.c = c;
}
public int getCount() {

    return elements.size();
}
public Object getItem(int position) {
    Collections.sort(elements, new IStatusUpdateComparator());
    return elements.get(position);
}
public long getItemId(int id) {
    return id;
}
public void Remove(int id)
{   
    notifyDataSetChanged();
}
public View getView(int position, View convertView, ViewGroup parent) 
{
    RelativeLayout rowLayout;
    IStatusUpdate t = elements.get(position);
            rowLayout = t.GetParent().GetUI(t, parent, c);
    return rowLayout;
}

class IStatusUpdateComparator implements Comparator
{
    public int compare(Object obj1, Object obj2)
    {
        IStatusUpdate update1 = (IStatusUpdate)obj1;
        IStatusUpdate update2 = (IStatusUpdate)obj2;
        int result = update1.getID().compareTo(update2.getID());

        if (result == -1)
        return 1;
        else if (result == 1)
        return 0;
        return result;
    }
}
}

Is there a better way to go about sorting ListViews in Android, while still being able to use the LayoutInflater? (rowLayout = t.GetParent().GetUI(t, parent, c) expands the UI to the specific view which the microblog implementation can provide)

  • 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-05-14T06:55:04+00:00Added an answer on May 14, 2026 at 6:55 am

    I wouldn’t recommend sorting the underlying list in getItem(), in my opinion a get..() method should be ‘idempotent’ and not have any externally-visible effect on its parent’s state.

    In the case of your problem I would tackle it at the point at which the tweets are added to the container. You haven’t included this part of your app source but it seems likely you are using an ArrayList. Perhaps you are querying the Twitter API for a list of tweets ordered most recently down, and calling add() on your ArrayList for each result, which is adding the tweets to the bottom of the list.

    Did you know you can insert at any point into an ArrayList? I would recommend reverse iterating through the results from the Twitter API and inserting each result at the top of your ArrayList with add(0, ….) rather than adding to the back of the list.

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

Sidebar

Ask A Question

Stats

  • Questions 448k
  • Answers 448k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Download an open-source project and look at their methods of… May 15, 2026 at 8:02 pm
  • Editorial Team
    Editorial Team added an answer You can use an EnhancedPatternLayout in log4j to format your… May 15, 2026 at 8:02 pm
  • Editorial Team
    Editorial Team added an answer If you look at the demo code at http://jqueryui.com/demos/slider/#range you… May 15, 2026 at 8:02 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.