0

난 그냥, 안드로이드 콘텐츠 공급자와 리졸버를 배우고 UserDataDictionary, 의 세부 사항을 인쇄하는 간단한 응용 프로그램을 만들려고 노력하지만 난 많은 항목이 있지만 커서의 수는 1으로 표시되며, 하나 개의 항목 만 인쇄하고 있습니다 내가 가서 사전의 모든 단어를 삭제하지만 여전히 그것은커서는 UserDataDictionary에서 마지막 항목 만 가져옵니다?

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     //Get and display the data dictionary 
     TextView dictionaryTextView=(TextView)findViewById(R.id.dictionary_text_view); 
     ContentResolver resolver=getContentResolver(); 
     //get cursor containing all words 
     Cursor cursor = resolver.query(UserDictionary.Words.CONTENT_URI, null, null, null, null); 
     String userDictString; 
     try { 

      //get total words 
      int numWords = cursor.getCount(); 
      //get all column Indexes 
      int columnIndex = cursor.getColumnIndex(UserDictionary.Words._ID); 
      int columnWords = cursor.getColumnIndex(UserDictionary.Words.WORD); 
      int columnFrequency = cursor.getColumnIndex(UserDictionary.Words.FREQUENCY); 

      userDictString=("The User dictionary Contains\n" +cursor.getCount()+" words\n"+UserDictionary.Words._ID +"\t\t"+UserDictionary.Words.WORD +"\t"+UserDictionary.Words.FREQUENCY+"\n"); 
      Log.d("Word",userDictString); 
      dictionaryTextView.setText(userDictString); 
      while (cursor.moveToNext())//zero if end of list in cursor(no more rows) 
      { 
       Log.d("Word",cursor.getString(columnWords)); 
       int id = cursor.getInt(columnIndex); 
       int frequency = cursor.getInt(columnFrequency); 
       String word = cursor.getString(columnWords); 
       dictionaryTextView.append(("\n" + id + " - " + frequency + " - " + word)); 
      } 

     } 
     catch (Exception e) 
     { 
      e.printStackTrace(); 
     } 

     finally { 
      cursor.close(); 
     } 


    } 
+0

참고 : 사전을 지우고 전화를 다시 시작해도 커서는 이전에 표시되지 않은 마지막 항목을 계속 표시합니다. –

답변

1

당신의 코드가 완벽하게 작동 아래 하나 개의 항목이, 난 그냥 안드로이드를 배우고, 어떤 도움을 주시면 감사하겠습니다 하나가 인쇄 한 OnCreate (0 방법을 참조 보여줍니다 내 전화에서. 방금 단어를 추가했지만 빈도 값의 기본값은 250입니다. 다른 전화에서 테스트 해보십시오.

+0

오, 좋아, 저는 HTC를 사용하고 있습니다. 제조업체가 때때로 물건을 바꾸는다고 생각합니다. 재고보다 삼성이 아주 다르 잖아,이게 그 원인 일까? –

+1

나는 말할 수 없다. 나는 Huawei를 사용했다. 나는 사전을 지우고, 단어를 추가하고, 단어를 제거하고, 각 작업에만 응답했습니다. 다시 스택에서 앱을 제거하고 다시 작업 사이에서 다시 시작해야했습니다. – Lema

관련 문제