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