난 그냥, 안드로이드 콘텐츠 공급자와 리졸버를 배우고 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();
}
}
참고 : 사전을 지우고 전화를 다시 시작해도 커서는 이전에 표시되지 않은 마지막 항목을 계속 표시합니다. –