首先對不起的過濾的ListView,我的英語安卓:如何用simpleCursorAdapter
我看過很多對於這個問題的答案,但我不知道該怎麼做我的代碼運行。
我想過濾我的listView與上面的EditText文本。
這裏是我的代碼:
private DbAdapter mDbHelper;
private EditText mSearch;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.baes_bat_list);
setTitle(R.string.baes_list_title);
mDbHelper = new DbAdapter(this);
mDbHelper.open();
fillData();
registerForContextMenu(getListView());
mSearch = (EditText) findViewById(R.id.searchbox);
}
private void fillData() {
String search = "";
search = mSearch.getText().toString();
// Get all of the rows from the database and create the item list
Cursor baesCursor = mDbHelper.fetchAllBaes(search);
startManagingCursor(baesCursor);
// Create an array to specify the fields we want to display in the list (only TITLE)
String[] from = new String[]{DbAdapter.BAES_NOM, DbAdapter.BAES_BAT};
// and an array of the fields we want to bind those fields to (in this case just text1)
int[] to = new int[]{R.id.text1, R.id.text2};
// Now create a simple cursor adapter and set it to display
// Now create a simple cursor adapter and set it to display
SimpleCursorAdapter baes =
new SimpleCursorAdapter(this, R.layout.baes_row, baesCursor, from, to);
setListAdapter(baes);
};
這裏是我的數據庫適配器
public Cursor fetchAllBaes(String string) {
String [] columns=new String[]{BAES_ID +" as _id",BAES_NOM,BAES_BAT,BAES_LOC,BAES_MISESERVICE,BAES_COUP,BAES_DATE_VISITE,BAES_ETAT, BAES_SYNC};
String [] search = null;
return mDb.query(TABLE_BAES, columns, BAES_BAT + "= ?", search, null, null, null);
}
我想我錯過了一步,但I'don't知道。感謝您的幫助。
只要使用這個鏈接... HTTP://mfarhan133.wordpress.com/2010/10/01/autocomplete- text-view/ –
我已經看到了關於這個主題的教程,但我不知道它是如何將數組適配器的過濾代碼調整到simplecursoradapter – gonzamax