마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

검색 부분 에러잡아주세요ㅜㅜ

0 추천

......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용량이 크기 때문일까요??와주세요ㅜㅜㅜㅜㅜㅜㅜㅜㅜ

 

 

익명사용자 님이 2014년 11월 13일 질문

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...