editText から入力を取得し、データベース内の検索結果を listView に表示する辞書を Android で作成しています。データベースには、単語と定義のセットが含まれています。ここに私が書いたコードの一部があります:
mEditText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
String query = getIntent().getStringExtra(SearchManager.QUERY);
showResults(query);
}
listView に検索結果を表示する必要がある showResults メソッドは次のとおりです。
private void showResults(String query) {
Cursor cursor = getContentResolver().query(DictionaryProvider.CONTENT_URI, null, null, new String[] {query}, null);
String[] from = new String[] { DictionaryDatabase.KEY_WORD, DictionaryDatabase.KEY_DEFINITION };
int[] to = new int[] { R.id.word, R.id.definition };
SimpleCursorAdapter words = new SimpleCursorAdapter(this, R.layout.result, cursor, from, to, RESULT_OK);
mListView.setAdapter((ListAdapter)words);
}
しかし、editText に入力を入力すると、結果が動的にリストされません。