I have created a table (TableLayout) which shows the amount of minutes used calling different contacts, like shown below:
Contact | Minutes Used
______________|__________________
|
Joe Bloggs | 5
Eric Peters | 10
John Smith | 53
Susan Jones | 9
I want to be able to order the rows so that they are in descending order of Minutes Used. Is this possible without first making my table into a database using SQLite? I haven’t used it before today and it seems like a very long way round what should be quite a simple thing.
I can post the code I use to create my table if needs be.
I would not use SQLite. Instead if you have one List of contacts and one List of minutes used, I would make a class Contact with the fields String name, and Int minutes. Then I would store those in a List and sort them by implementing Comparable (an interface) on the Contact class. Comparable: (http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Comparable.html).
Comparable explained:
you need to implement the method “public int CompareTo(Object o)”. This should return 1 if theres more minutes, 0 if theres the same amount and -1 if theres less. Then you can sort your Contact objects painlessly.
Remember to cast the object as a Contact, and have a way to access the number of minutes, such as public int getMinutes() to call on a Contact instance.
Also note you will most likely have to programmatically create your layout with anonymous table rows and setting each textview in the table row from the fields of a Contact object.