0

我有这段代码,我在由 CursorAdapter 支持的 ListView 中过滤结果。

这是 databaseHelper 方法:

public Cursor getCategoryCursor(String constraints){

    Cursor c = null;
    if(constraints=="")
    c=database.query("categoryTable", null , null, null, null, null, "category_name COLLATE NOCASE ASC");

    else
        c=database.rawQuery("SELECT category_name,_id FROM categoryTable WHERE category_name LIKE '%"+constraints+"%'", null);
    return c;
}

定义此方法后,我在 EditText 上设置 onTextChangeListener,如下所示:

@Override
public void afterTextChanged(Editable arg0) {
    // TODO Auto-generated method stub
    ListView cLV=(ListView)InteractiveVoucher.this.findViewById(R.id.category_list);
    CursorAdapter filterAdapter=(CursorAdapter)cLV.getAdapter();
    filterAdapter.getFilter().filter(arg0.toString());
}

最后,当我运行代码时,我在 adapterCalss 的这一行得到错误:

public void bindView(View view, Context context, Cursor cursor) {
    // TODO Auto-generated method stub
    TextView tv=(TextView)view.findViewById(R.id.category_name);
            //get the error on getColumnIndex() line
    tv.setText(mCursor.getString(mCursor.getColumnIndex(mColumnName)));
    tv.setTextSize(20);
4

0 回答 0