私は完全に困惑しています!私は年齢を探していますが、解決策を見つけることはできません。私はそれが本当に簡単になるだろうという気持ちがあります!ユーザーがテキストを入力しているときにカーソルを使用してリストビューを更新する方法
私はカーソルに拘束されたリストビューを持っています。ユーザが文字を入力するたびに、リストビューはデータベースを検索して結果を返します。それはかなり簡単ですが、私はそれを理解することはできません。助けを前にありがとう。ここで
は、私が持っているコードは、これまでのところです:
private Cursor mCursor;
@Override
public void onCreate(Bundle icicle) {
mCursor = myDb.startsWith("a");
}
はその後、私の例では、私がされたCharSequenceの頭文字を取っていますが、これがない場合があります。
public class MyList extends ListActivity {
public static final String KEY_ROWID = "headwords._id";
public static final String KEY_WORDS = "headwords.words";
private ListAdapter adapter;
private DbManager myDb;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.item_list);
myDb = new DbManager(this);
myDb.open();
Cursor mCursor = myDb.startsWith("a");
startManagingCursor(mCursor);
try {
adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, mCursor,
new String[] { KEY_WORDS, KEY_ROWID },
new int[] { android.R.id.text1, android.R.id.text2 });
setListAdapter(adapter);
} catch (Exception e) {
Log.i("adapter error Here!", ">>>>>>>>>>> Error!" + e.toString());
}
EditText myET = (EditText) findViewById(R.id.search_text);
myET.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
//code which would change listview to only show item that match what is being typed in
}
@Override
public void afterTextChanged(Editable s) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
});
}
mCursorを最後にして、onTextChangedでmCursor.requery()を呼び出します。 – Gopal
クエリーは以前と同じクエリーではないため、クエリーは機能しません。 –