0
パブリッククラスMainActivityはAppCompatActivity/* {Androidのユーザー辞書からデータにアクセス中にカーソルがエラーを起こしていますか?私は、メモリリークが発生しますcusorを閉じていない場合は
// For the SimpleCursorAdapter to match the UserDictionary columns to layout items.
private static final String[] COLUMNS_TO_BE_BOUND = new String[]{
UserDictionary.Words.WORD,
UserDictionary.Words.FREQUENCY
};
private static final int[] LAYOUT_ITEMS_TO_FILL = new int[]{
android.R.id.text1,
android.R.id.text2
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Get the TextView which will be populated with the Dictionary ContentProvider data.
ListView dictListView = (ListView) findViewById(R.id.dictionary_list_view);
//TextView dictTextView = (TextView) findViewById(R.id.dictionary_text_view);
Cursor cursor = null;
try {
// Get the ContentResolver which will send a message to the ContentProvider.
ContentResolver resolver = getContentResolver();
// Get a Cursor containing all of the rows in the Words table.
cursor = resolver.query(UserDictionary.Words.CONTENT_URI, null, null, null, null);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
android.R.layout.two_line_list_item,
cursor,
COLUMNS_TO_BE_BOUND,
LAYOUT_ITEMS_TO_FILL,
0
);
dictListView.setAdapter(adapter);
} catch (Exception e) {
e.getMessage();
} finally {
cursor.close();
}
}
}
を拡張します。しかし、それはコンパイラによって表示されませんでした! ここで何が起こっているのか正確に知りたいですか? ありがとうございます! */
使用し終わるまで、カーソルをアダプタで閉じることはできません – tyczj