......SD카드의 asset폴더안에 DB파일을 복사.....
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.caldic);
....
try {
Cursor cursor;
SQLiteDatabase db = SQLiteDatabase.openDatabase(DB_PATH+DB_NAME, null, 1);//sqlite도우미로 db선언하고
String[] FROM = { "*" }; //foodcala테이블의 컬럼선택
cursor = db.query("foodcala", FROM, null, null, null, null, null);
startManagingCursor(cursor);
foodsList = new String[cursor.getCount()]; //배열초기화
calList = new String[cursor.getCount()];
gramList = new String[cursor.getCount()];
while(cursor.moveToNext()) //배열에 저장
{
String foods = cursor.getString(1);
String cal = cursor.getString(2);
String gram = cursor.getString(3);
foodsList[listcount] = foods;
calList[listcount] = cal;
gramList[listcount] = gram;
listcount++;
}
if(db != null)
db.close();
} catch (Exception e) {
Toast.makeText(this, "ERROR IN CODE:"+e.toString(), Toast.LENGTH_LONG).show();
}
if (listcount > 0)
{
ArrayList<String> listString = new ArrayList<String>(); //문재배열초기화
for (int i = 0; i < foodsList.length; i++) //list수만큼대입
{
listString.add(foodsList[i]+" "+calList[i]+"kcal");//+" ("+gramList[i]+"gram)");
}
ListView listView = (ListView)findViewById(R.id.list); //리스트뷰에연결
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getBaseContext(),
android.R.layout.simple_list_item_1, listString);
listView.setAdapter(arrayAdapter);
}
}
//자음
private static final char[] INITIAL_SOUND = {
'ㄱ', 'ㄲ', 'ㄴ', 'ㄷ', 'ㄸ', 'ㄹ', 'ㅁ', 'ㅂ', 'ㅃ',
'ㅅ', 'ㅆ', 'ㅇ', 'ㅈ', 'ㅉ', 'ㅊ', 'ㅋ', 'ㅌ', 'ㅍ', 'ㅎ'
};
....................
@Override
public boolean onKeyDown(int keyCode, KeyEvent event){
if(keyCode==84)
{//검색 테스트박스에 문자열
String s = input.getText().toString();
if(s.length()>0){
String r="";
for(int i = 0; i<s.length(); i++)
{
char a=s.charAt(i); //s문자열의 i 번째 문자 대입
if(isInitialSound(a))
r+=a;
else if(a==' ')
r+="";
}
Toast.makeText(this,r, Toast.LENGTH_LONG).show();
listString.clear();
for(int i = 0; i<foodsList.length; i++)
{
//한글이랑 결과 문자열과 비교 일치하면 문자열 배열에 한글과 크메르어 추가
if(matchString(foodsList[i],r))listString.add(foodsList[i] + calList[i]);
}}
arrayAdapter.notifyDataSetChanged();//배열 어댑터 리셋
}
return super.onKeyDown(keyCode, event);
}
}
edittext 는 imeoptions = actionsearch로 설정해주었고실행하면목록은불러오지만 검색결과는 리스트뷰로 뿌리지 못합니다. 검색하면 unregisterIRListener()가뜹니다.또 시간이 지나면 아무 동작이 없어도 이 페이지가 죽는데 이건 db용량이 크기 때문일까요??와주세요ㅜㅜㅜㅜㅜㅜㅜㅜㅜ