프로그래밍 정리/안드로이드

디비 초성검색

주누다 2012. 7. 10. 16:24
반응형

//디비 초성검색을 위해 

private String HangleDatabaseSearch (String aSearch)

{

//검색어에 작은따옴표 입력 죽는 현상 예외처리(작은 따옴표 검색 제외)

  if( aSearch.contains("'") )  aSearch = aSearch.replace("'", "");

 

String search = null;

if(aSearch.equals("ㄱ"))

search = "SELECT content FROM search WHERE content >='가' and content < '나'";//"SELECT * FROM search WHERE content between 'ㄱ' AND '깋'";

else if(aSearch.equals("ㄴ"))

search = "SELECT content FROM search WHERE content >='나' and content < '다'";

else if(aSearch.equals("ㄷ"))

search = "SELECT content FROM search WHERE content >='다' and content < '라'";

else if(aSearch.equals("ㄹ"))

search = "SELECT content FROM search WHERE content >='라' and content < '마'";

else if(aSearch.equals("ㅁ"))

search = "SELECT content FROM search WHERE content >='마' and content < '바'";

else if(aSearch.equals("ㅂ"))

search = "SELECT content FROM search WHERE content >='바' and content < '사'";

else if(aSearch.equals("ㅅ"))

search = "SELECT content FROM search WHERE content >='사' and content < '아'";

else if(aSearch.equals("ㅇ"))

search = "SELECT content FROM search WHERE content >='아' and content < '자'";

else if(aSearch.equals("ㅈ"))

search = "SELECT content FROM search WHERE content >='자' and content < '차'";

else if(aSearch.equals("ㅊ"))

search = "SELECT content FROM search WHERE content >='차' and content < '카'";

else if(aSearch.equals("ㅋ"))

search = "SELECT content FROM search WHERE content >='카' and content < '타'";

else if(aSearch.equals("ㅌ"))

search = "SELECT content FROM search WHERE content >='타' and content < '파'";

else if(aSearch.equals("ㅍ"))

search = "SELECT content FROM search WHERE content >='파' and content < '하'";

else if(aSearch.equals("ㅎ"))

search = "SELECT content FROM search WHERE content >='하' and content < '힣'";

else

search = "SELECT * FROM search WHERE content LIKE '%" + aSearch + "%'" ;

return search;

}


    // EditText 입력시마다 수행되어야 하는 '사용자 정의 이벤트'

    TextWatcher textWatcher = new TextWatcher() {

@Override

public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {

if(arg0.length() != 0 && mInputSearch.hasFocus())

{

//where ename like '김%

String query = HangleDatabaseSearch(arg0.toString());

MyLog.e(ContentStore.LOG_TAG, "query : " + query);

openDataBase();

mCorsor = mDB.rawQuery(query, null);

mRecentSearchDropdown = new ArrayList<String>();

if (mCorsor != null && mCorsor.getCount()!=0) {

if(mCorsor.moveToLast())

{

do

{

String search = mCorsor.getString(mCorsor.getColumnIndex("content"));

MyLog.e(ContentStore.LOG_TAG, "search : " + search);

mRecentSearchDropdown.add(search);

} while(mCorsor.moveToPrevious());

recentDropdownAA = 

new ArrayAdapter<String>(mCtx, R.layout.store_recent_list, R.id.store_recent_list, mRecentSearchDropdown);

mDetailListView.setAdapter(recentDropdownAA);

mCorsor.close();

mDetailListView.setVisibility(View.VISIBLE);

setChangeInputSearchBackground();

}

       }

mInputSearch.visibleInputBoxInitBtn();

}

else

{

mDetailListView.setVisibility(View.INVISIBLE);

mInputSearch.invisibleInputBoxInitBtn();

setInitInputSearchBackground();

}

}


@Override

public void afterTextChanged(Editable s) {}


@Override

public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

    };

반응형