1. 程式人生 > >聯絡人按照拼音首字母排序

聯絡人按照拼音首字母排序

                       //getFirstLetter() 為ContactEntity類裡的一個方法,聯絡人拼音全稱.charAt(0)就可以得到
switch(contactlist.get(i).getFirstLetter()){
case 'a':
position[i]=1;
break;
case 'b':
position[i]=2;
break;
case 'c':
 position[i]=3;
break;
case 'd':
position[i]=4;
break;
case 'e':
 position[i]=5;
break;
case 'f':
 position[i]=6;
break;
case 'g':
 position[i]=7;
break;
case 'h':
position[i]=8;
break;
case 'i':
position[i]=9;
break;
case 'j':
position[i]=10;
break;
case 'k':
 position[i]=11;
break;
case 'l':
position[i]=12;
break;
case 'm':
position[i]=13;
break;
case 'n':
position[i]=14;
break;
case 'o':
position[i]=15;
break;
case 'p':
position[i]=16;
break;
case 'q':
        position[i]=17;
break;
case 'r':
position[i]=18;
break;
case 's':
 position[i]=19;
break;
case 't':
 position[i]=20;
break;
case 'u':
 position[i]=21;
break;
case 'v':
 position[i]=22;
break;
case 'w':
position[i]=23;
break;
case 'x':
position[i]=24;
break;
case 'y':
position[i]=25;
break;
case 'z':
 position[i]=26;
break;
 default:
  position[i]=0;
break;
}
  }
//mTempArrayList 數組裡的聯絡人首字元的標識完了以後就可以按照從0—26的順序一個一個往新的ArrayLlist           //添加了

  for(int j=0;j<27;j++){
  for(int a=0;a<position.length;a++){
  if(j==position[a]){
newsortList.add(contactlist.get(a));
 
}
 
 }
Log.i(TAG,"The newsortList size is "+newsortList.size());  
 }
  return newsortList;
}
   }