0

可能重复:
光标 setFilterQueryProvider 问题

我正在尝试为我的列表视图设置一个编辑文本过滤器。

目前我有以下代码,但在我的 cursorAdapter 对象上的“setFilterQueryAdapter”上不断出现错误。

我的“OnCreate 方法”中有此代码,并且由于其中一个错误声称“void”的返回类型不正确,我认为它应该不在 onCreate 中,但我不确定在哪里。

希望有人能告诉我哪里出错了。这是代码:

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


setContentView(R.layout.appointmentview);

searchedAppView = (ListView)findViewById(android.R.id.list);

searchAppoints = (ImageButton) findViewById(R.id.btnSearchAppointName); 
searchAppName = (EditText) findViewById(R.id.inputAppointName); 

    DBHandlerApp DBAppointments = new DBHandlerApp(this, null, null);

    DBHandlerApp searchApps = new DBHandlerApp(this, null, null);

    searchApps.open();


    Cursor cursor = searchApps.getAppointmentsData();
     searchApps.close();
    startManagingCursor(cursor);




    String [] from = new String [] {DBAppointments.KEY_NAMEAPP, DBAppointments.KEY_TYPEAPP, DBAppointments.KEY_TIMEAPP, DBAppointments.KEY_DATEAPP, DBAppointments.KEY_COMMENTAPP};
    int [] to = new int [] {R.id.txtAppointName, R.id.txtAppointType, R.id.txtAppointTime, R.id.txtAppointDate, R.id.txtAppointCom};






    cursorAdapter = new SimpleCursorAdapter(this, R.layout.setappointviews, cursor, from, to);
    searchedAppView.setAdapter(cursorAdapter);

    searchedAppView.setTextFilterEnabled(true);

    searchAppoints.setOnClickListener(this);



    searchAppName.addTextChangedListener(new TextWatcher()
     {

        @Override
        public void onTextChanged(CharSequence s, int start, int before,
                int count) {


        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {


        }

        @Override
        public void afterTextChanged(Editable s) {



                cursorAdapter.getFilter().filter(s.toString());

        }


     });

    DBHandlerApp changedAppoint = new DBHandlerApp (this, null, null);

             ********** ERROR **********
     cursorAdapter.setFilterQueryProvider(FilterQueryProvider()
    {
        public Cursor runQuery(CharSequence constraint)
        {
            changedAppoint.open();
            return changedAppoint.getChanges(constraint.toString());

        }
    });


    };
4

1 回答 1

0

设法自己解决了这个问题。这主要是因为我没有导入“FilterQueryProvider”。

于 2013-02-04T21:13:03.397 回答