如何在创建Listview后重置SQLite查询?

时间:2011-02-25 15:59:20

标签: android sqlite

我有一个ListView,它使用以下代码在OnCreate中填充SQLite查询,然后设置OnItemClickListener。

ListView menuList = (ListView) findViewById(R.id.ListView_Menu);

String sql = "SELECT EXHIBITORS, ('Stand No. ' || STANDNO) AS STANDNO, _ID FROM EXHIBITOR ORDER BY EXHIBITORS";
cursor = myDbHelper.getReadableDatabase().rawQuery(sql, null);

startManagingCursor(cursor);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.menu_item, cursor, FROM, TO);
menuList.setAdapter(adapter);

menuList.setOnItemClickListener(new AdapterView.OnItemClickListener() {

public void onItemClick(AdapterView<?> parent, View itemClicked, int position, long id) {

但是,我希望能够过滤ListView,然后修改查询,以便用户可以通过请求所有以字母“A”开头的参展商来减小ListView的大小。我怎么能这样做,我假设再次使用上面的代码但是我如何保持OnItemClickListener的工作呢?

1 个答案:

答案 0 :(得分:1)

CursorAdapter.changeCursor()将允许您用过滤参展商名称的查询替换您的查询。