ArrayList sorting issue in Android -
i've arraylist of objects.
arraylist<item> blog_titles = new arraylist<item>(); i want sort arraylist in descending order of 1 of datamembers datetime value stored string (timestamp in code below).
public class blogitem implements item, comparable<blogitem> { public final string id; public final string heading; public final string summary; public final string description; public final string thumbnail; public final string timestamp; // format:- 2013-02-05t13:18:56-06:00 public final string blog_link; public blogitem(string id, string heading, string summary, string description, string thumbnail, string timestamp, string blog_link) { this.id = id; this.heading = heading; this.summary = summary; this.description = description; this.thumbnail = thumbnail; this.timestamp = timestamp; // format:- 2013-02-05t13:18:56-06:00 this.blog_link = blog_link; } @override public int compareto(blogitem o) { // todo auto-generated method stub return this.timestamp.compareto(o.timestamp); } } item generic interface:
public interface item { // todo auto-generated method stub } now when i'm trying sort arraylist like:
collections.sort(blog_titles); i following error message:
bound mismatch: generic method sort(list<t>) of type collections not applicable arguments (arraylist<item>). inferred type item not valid substitute bounded parameter <t extends comparable<? super t>> how fix above error & correct approach sort arraylist in case ?
your blog_titles list list of item.
item not comparable, while blogitem is.
either declare blog_titles arraylist<blogitem>, or make item extend comparable
Comments
Post a Comment