简体   繁体   English

Blackberry-按日期对ListField数据进行排序

[英]Blackberry - Sort ListField data by date

I have got data from XML parsing, and try to sort it based on date which has format like "Wed, 06 Jun 2012 09:53:05 +0700". 我从XML解析中获取了数据,并尝试根据日期进行排序,该日期的格式为“ Wed,06 Jun 2012 09:53:05 +0700”。 So all news from every provider will be mixed and organized from the latest to the newest. 因此,来自每个提供商的所有新闻将按照最新消息进行混合和整理。

Here is the code: 这是代码:

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++;
}

so, before I add it into the row, it will be sorted first. 因此,在将其添加到行之前,将首先对其进行排序。 Can anyone help me? 谁能帮我?

try this - 尝试这个 -

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;
  }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM