Blackberry - 按日期排序ListField数据

时间:2012-06-06 03:41:50

标签: sorting blackberry labelfield pubdate

我从XML解析中获取数据,并尝试根据具有“Wed,06 Jun 2012 09:53:05 +0700”等格式的日期对其进行排序。所以来自每个提供商的所有新闻都将从最新到最新的混合和组织。

以下是代码:

int i=0;
while (i<vec.size()){

    row = new TableRowManager();

    prov = new LabelField(((BinNews)vec.elementAt(i)).getProv(),DrawStyle.ELLIPSIS){
        protected void paint(Graphics g) {
            g.setColor(Color.ORANGERED);
            super.paint(g);
        }
    };

    title = new LabelField(((BinNews)vec.elementAt(i)).getTitle(),DrawStyle.ELLIPSIS){
        protected void paint(Graphics g) {
            g.setColor(Color.BLUE);
            super.paint(g);
        }
    };
    title.setFont(Font.getDefault().derive(Font.BOLD));

    desc = new LabelField(((BinNews)vec.elementAt(i)).getDesc(),DrawStyle.ELLIPSIS){
        protected void paint(Graphics g) {
            g.setColor(Color.BLACK);
            super.paint(g);
        }
    };

    date = new LabelField(((BinNews)vec.elementAt(i)).getDate(),DrawStyle.ELLIPSIS){
        protected void paint(Graphics g) {
            g.setColor(Color.ORANGERED);
            super.paint(g);
        }
    };

    rows.addElement(row);
    setSize(rows.size());
    row.add(prov);
    row.add(date);
    row.add(title);
    row.add(desc);
    i++;
}

所以,在我将它添加到行之前,它将首先排序。任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

试试这个 -

public static SimpleSortingVector  vector = new SimpleSortingVector ();


vector.setSortComparator(new MyComparator());
vector.addElement(new FriendsRequestObject(id_,name_));
vector.reSort();    



import net.rim.device.api.util.Comparator;
public class MyComparator implements Comparator {
 public int compare(Object o1, Object o2) {
    FriendsRequestObject f1 = (FriendsRequestObject)o1;
    FriendsRequestObject f2 = (FriendsRequestObject)o2;

    return f1.getSender_name().compareTo(f2.getSender_name());
  }

  public boolean equals(Object obj) {
    return compare(this, obj) == 0;
  }

}