현재 db에서 '좋아요'순으로 정렬해서 높은수에서 낮은수로 차례대로 리스트뷰에 뿌려지게 하려고합니다.
Collections.sort를 사용했는데 먹히질않아요....뭐가문제인가요?
protected void showList(){
try {
JSONObject jsonObj = new JSONObject(myJSON);
peoples = jsonObj.getJSONArray(TAG_RESULTS);
ArrayList<String> strList = new ArrayList<String>() ; <--좋아요수를 담을 어레이리스트.
for(int i=0;i<peoples.length();i++){
JSONObject c = peoples.getJSONObject(i);
String no = c.getString(TAG_NO);
String likes= c.getString(TAG_LIKES);
strList.add(likes); <--좋아요수 를 어레이에 저장.
Log.d("sort",strList+""); <-- 로그를 통해서 확인결과 [0, 0, 1, 1, 1, 2, 3, 4, 62, 0] <-제대로 찍힙니다.
HashMap<String,String> persons = new HashMap<String,String>();
persons.put(TAG_NO,no);
persons.put(TAG_LIKES,likes);
personList.add(persons);
final Comparator<String> myComparator= new Comparator<String>(){
private final Collator collator = Collator.getInstance();
@Override
public int compare(String o1, String o2) {
return o1.compareTo(o2);
}
};
Collections.sort(strList ,myComparator);
for (String str : strList) {
Log.d("str",str);
//System.out.println(str) ;
}
}
final ListAdapter adapter = new SimpleAdapter(
Main_Page.this, personList,
R.layout.list_item,
new String[]{TAG_NAME,,TAG_LIKES},
new int[]{ R.id.name,,R.id.textlike}
)