How to add an item in sorted order in listview?

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

How to add an item in sorted order in listview?

Postby jclova » Thu Nov 12, 2009 4:03 pm

I know if you're to display entire list in sorted order,
simply do 'ORDER BY' to sort database cursor.

However, I have a thread to insert a new item.
How can I add so that it doesn't add at the bottom but add in sorted order?

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3. list.clear();
  4.  
  5. for (int i = 0; i < c.getCount(); i++)
  6.  
  7. {
  8.  
  9.      list.add(item);
  10.  
  11. }
  12.  
  13. myAdapter.setListItems(list)
  14.  
  15. this.setListAdapter(myAdapter);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Isn't this inefficient?

is there a way to:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3. list.add(item);
  4.  
  5. myAdapter.addItem(item)
  6.  
  7. this.setListAdapter(myAdapter);
Parsed in 0.030 seconds, using GeSHi 1.0.8.4

But to add in sorted order?

Thanks in advance~!
jclova
Freshman
Freshman
 
Posts: 3
Joined: Tue Oct 20, 2009 9:33 pm

Top

Postby qlimax » Thu Nov 12, 2009 7:12 pm

more info pls... :?
btw, what I can say you now, is to take a look here (sorting lists)

http://java.sun.com/javase/6/docs/api/j ... tions.html
at the sort method.


bye
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 7 guests