本文整理匯總了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);
}