현재 헤더 인덱스에 초성이 나오고 새로 인덱스에 초성이 나오는것 까진 만들었는데.
세로인덱스에서 초성을 누르면 스크롤이 움직여서 해당 초성이 있는곳으로 가고싶은데
입력된 이름의 성 예를들어 가나다 면 가를 세로인덱스에 넣고 가를 누르면 스크롤이 움직이는데
초성을 입력해서 초성을 누르면 반응을 안합니다.;; 도대체 어떻게해야할지 모르겠습니다..ㅠ
<Adapter부분>
public int getPositionForSection(int section) {
if(section == 35){ //섹션의 아스키값이 35일 경우 0번째를 반환합니다. 아마 특수문자 였던듯 ㅡ.ㅡ;
return 0;
}//전체 데이터를 순회하면서 첫문자열을 비교합니다.
for(int i = 0 ; i < Listuser_list.size();i++){
String fiRst = Listuser_list.get(i).getUserName();
char firstChar = fiRst.charAt(0);//대문자 변환후 첫번째 문자열을 가져옵니다.
if(firstChar == section){//첫번째 문자열과 섹션에 표시될 문자열을 비교합니다.
return i;//같다면 해당 인덱스를 반환합니다.
}
}
return -1;
}
public String Direct(String name) {
char b =name.charAt(0);
String chosung = null;
int first = (b - 44032 ) / ( 21 * 28 );
switch(first){
case 0:
case 1:
chosung="ㄱ";
break;
case 2:
chosung="ㄴ";
break;
case 3:
case 4:
chosung="ㄷ";
break;
case 5:
chosung="ㄹ";
break;
case 6:
chosung="ㅁ";
break;
case 7:
case 8:
chosung="ㅂ";
break;
case 9:
case 10:
chosung="ㅅ";
break;
case 11:
chosung="ㅇ";
break;
case 12:
case 13:
chosung="ㅈ";
break;
case 14:
chosung="ㅊ";
break;
case 15:
chosung="ㅋ";
break;
case 16:
chosung="ㅌ";
break;
case 17:
chosung="ㅍ";
break;
case 18:
chosung="ㅎ";
break;
}
return chosung;
}
<IndexBar 부분>
private void init() {
l = new char[]{
'ㄱ','ㄴ','ㄷ','ㄹ','ㅁ','ㅂ','ㅅ','ㅇ','ㅈ','ㅊ','ㅋ','ㅌ','ㅍ','ㅎ','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'
};//index에 표시될 문자들.
setBackgroundColor(0x44FFFFFF);
}
public boolean onTouchEvent(MotionEvent event) {
super.onTouchEvent(event);
int size = getMeasuredHeight()/(l.length+1);
int i = (int)event.getY();
int idx = i/size;
if(idx >= l.length){
idx = l.length-1;
}else if(idx < 0){
idx = 0;
}
if(event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE){
if(sectionIndexter == null){
sectionIndexter = (SectionIndexer) list.getAdapter();
}
int position = sectionIndexter.getPositionForSection(l[idx]);
if(position == -1){
return true;
}
list.setSelection(position);
}
return true;
}