本文整理汇总了Java中net.rim.device.api.util.Comparator类的典型用法代码示例。如果您正苦于以下问题:Java Comparator类的具体用法?Java Comparator怎么用?Java Comparator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Comparator类属于net.rim.device.api.util包,在下文中一共展示了Comparator类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sortedUsers
import net.rim.device.api.util.Comparator; //导入依赖的package包/类
static RichVector sortedUsers(Users users) {
final RichVector listItems = new RichVector();
char last = ' ';
SimpleSortingVector v = new SimpleSortingVector();
v.setSortComparator(new Comparator() {
public int compare(Object o1, Object o2) {
if (o1 instanceof User && o2 instanceof User) {
return ((User) o1).getFullName().compareTo(((User) o2).getFullName());
} else {
return 0;
}
}
});
for (int i = 0; i < users.size(); ++i) {
v.addElement(users.getObject(i));
}
v.reSort();
for (int i = 0; i < v.size(); ++i) {
if (v.elementAt(i) instanceof User) {
User u = (User) v.elementAt(i);
char c = u.getFullName().charAt(0);
if (c != last) {
listItems.addElement(new SeparatorItem(c + ""));
last = c;
}
listItems.addElement(new UserItem(u));
}
}
return listItems;
}
示例2: FriendSelector
import net.rim.device.api.util.Comparator; //导入依赖的package包/类
FriendSelector(JSONObject Current, UiApplication app) {
int direction = Display.DIRECTION_NORTH;
Ui.getUiEngineInstance().setAcceptableDirections(direction);
this.setTitle(" CrapSnap - Select Receiver...");
Bitmap back = EncodedImage.getEncodedImageResource("Back.jpg")
.getBitmap();
this.setBackground(BackgroundFactory.createBitmapBackground(back));
monApp = app;
Send.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
exitbol = false;
if (CheckBox.getChecked() == true) {
storybol = true;
}
quit();
}
});
String[] names;
try {
JSONArray friends = Current.getJSONArray("friends");
names = new String[friends.length()];
for (int i = 0; i < friends.length(); i++) {
JSONObject friend = friends.getJSONObject(i);
names[i] = friend.getString("name");
}
Comparator strComparator = new Comparator() {
public int compare(Object o1, Object o2) {
return o1.toString().compareTo(o2.toString());
}
};
Arrays.sort(names, strComparator);
for (int i = 0; i < names.length; i++) {
ListManager.add(new FriendSelectorObject(names[i]));
ListManager.add(new SeparatorField());
}
} catch (JSONException e) {
e.printStackTrace();
}
this.addMenuItem(AddMenuItem);
this.addMenuItem(CancelMenuItem);
BtnManager.add(Send);
MainManager.add(ListManager);
HorizontalFieldManager StoryManager = new HorizontalFieldManager();
CheckBox.setFont(CheckBox.getFont().derive(Font.BOLD, 9, Ui.UNITS_pt));
StoryManager.add(new LabelField(" "));
StoryManager.add(CheckBox);
MainManager.add(StoryManager);
MainManager.add(BtnManager);
this.add(MainManager);
}