Collections sort(students, new Comparator<Student>() {
public int compare(Student s1,Student s2) {
if(s1.getName() != null && s2.getName() != null
&& s1.getName().comareTo(s1.getName()) != 0) {
return s1.getName().compareTo(s2.getName());
}
else {
return s1.getAge().compareTo(s2.getAge());
}
}
);
본문
http://stackoverflow.com/questions/14154127/collections-sortlistt-comparator-super-t-method-example
또는
02 | List<custom> myArrayData = new ArrayList<custom>(); |
05 | for ( int i = 0 ; i < downMyData.size(); i++) { |
06 | myArrayData.add(downMyData.get(i)); |
12 | private final static Comparator<custom> myComparator = new Comparator<custom>() { |
13 | private final Collator collator = Collator.getInstance(); |
15 | public int compare(custom object1,custom object2) { |
16 | return collator.compare(object1.getData(), object2.getData()); |
22 | Collections.sort(myArrayData ,myComparator); |
26 | ListView MyListView = (ListView)findViewById(R.id.mylistview); |
27 | MyAdapter adapter = new MyAdapter ( this ,R.layout.my_item,myArrayData ); |
28 | MyListView.setAdapter(adapter); |
본문
http://devbible.tistory.com/23
댓글 없음:
댓글 쓰기