안드로이드 개발 질문/답변
(글 수 45,052)
안녕하세요~
주소록에서 이름과 전화번호를 가져오는 가져오는 부분을 만들고 있는데요~
java를 이용해 초성검색을 하는 소스는 인터넷상에 구할수가 있어서 사용하고 있습니다.
그런데 sqlite 를 사용해 초성검색을 하면 좀 더 빠르게 검색되지 않을까 해서
고수님의 의견을 듣고자 글을 올려봅니다;;
먼저 지금 전화번호와 이름을 가져오는 소스입니다.
이렇게 하려고 했는데 where 가 부분에서 에러가 발생하는데 문법이 틀린것인지.....어쩐것인지
알려주시면 감사하겠습니다~
주소록에서 이름과 전화번호를 가져오는 가져오는 부분을 만들고 있는데요~
java를 이용해 초성검색을 하는 소스는 인터넷상에 구할수가 있어서 사용하고 있습니다.
그런데 sqlite 를 사용해 초성검색을 하면 좀 더 빠르게 검색되지 않을까 해서
고수님의 의견을 듣고자 글을 올려봅니다;;
먼저 지금 전화번호와 이름을 가져오는 소스입니다.
public ArrayList<AddressBookData> getPhoneNameNumber() {
ArrayList<AddressBookData> list = new ArrayList<AddressBookData>();
String[] projection = new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER };
String where = "case when "+ContactsContract.Contacts.DISPLAY_NAME + "< 'ㄱ' then SUBSTRING("+
ContactsContract.Contacts.DISPLAY_NAME+",1,1) when ascii('ㄱ') <= ascii("+
ContactsContract.Contacts.DISPLAY_NAME + ") and "+
"ascii("+ContactsContract.Contacts.DISPLAY_NAME+
"<= ascii('ㅎ') then "+ContactsContract.Contacts.DISPLAY_NAME+
"when "+ContactsContract.Contacts.DISPLAY_NAME + " < '나' then 'ㄱ' "+
"when "+ContactsContract.Contacts.DISPLAY_NAME + " < '다' then 'ㄴ' "+
"when "+ContactsContract.Contacts.DISPLAY_NAME + " < '라' then 'ㄷ' "+
"when "+ContactsContract.Contacts.DISPLAY_NAME + " < '마' then 'ㄹ' "+
"when "+ContactsContract.Contacts.DISPLAY_NAME + " < '바' then 'ㅁ' "+
"when "+ContactsContract.Contacts.DISPLAY_NAME + " < '사' then 'ㅂ' "+
"when "+ContactsContract.Contacts.DISPLAY_NAME + " < '아' then 'ㅅ' "+
"when "+ContactsContract.Contacts.DISPLAY_NAME + " < '자' then 'ㅇ' "+
"when "+ContactsContract.Contacts.DISPLAY_NAME + " < '차' then 'ㅈ' "+
"when "+ContactsContract.Contacts.DISPLAY_NAME + " < '카' then 'ㅊ' "+
"when "+ContactsContract.Contacts.DISPLAY_NAME + " < '타' then 'ㅋ' "+
"when "+ContactsContract.Contacts.DISPLAY_NAME + " < '파' then 'ㅌ' "+
"when "+ContactsContract.Contacts.DISPLAY_NAME + " < '하' then 'ㅍ' "+
"else 'ㅎ' end = '" + searchKeyword +"'";
Cursor cursor = managedQuery(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, projection, where, null, ContactsContract.Contacts.DISPLAY_NAME + " ASC");
if (null != cursor) {
try {
while (cursor.moveToNext()) {
String phoneNumber = CommonUtil.removeNonDigit(cursor.getString(2));
if (CommonUtil.isPhoneNumberValid(phoneNumber) ) {
addContact(list, cursor.getString(1), CommonUtil.removeNonDigit(cursor.getString(2)));
}
}
} finally {
cursor.close();
}
}
return list;
}
이렇게 하려고 했는데 where 가 부분에서 에러가 발생하는데 문법이 틀린것인지.....어쩐것인지
알려주시면 감사하겠습니다~



