光标s​​etFilterQueryProvider问题 [英] Cursor setFilterQueryProvider issue

查看:279
本文介绍了光标s​​etFilterQueryProvider问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图筛选从我的数据库处理程序类通过使用上的简单的游标适配器类的setFilterQueryProvider'的返回游标的结果。目前,我在下面的方法获得多个错误:

当前错误:

错误1:

 的方法FilterQueryProvider()是未定义的类型ViewAppointments。
 

错误2:

 语法错误,插入;完成陈述。
 

错误3:

 非法修改为变量runQuery;只有最终被允许
 

错误4:

 令牌),语法错误;预期
 

错误5:

 太虚方法不能返回值。
 

错误6:

 语法错误令牌),删除此令牌。
 

以上错误注意以下code:

  DBHandlerApp changedAppoint =新DBHandlerApp(这一点,NULL,NULL);

             //对FilterQueryProvider'和ERROR 2结束),ERROR 1。
     cursorAdapter.setFilterQueryProvider(FilterQueryProvider()

            {

            //对runQuery错误3。错误4月底)。
        公共光标runQuery(CharSequence的约束)
        {
                //错误5。
            返回changedAppoint.getChanges(constraint.toString());

        }
        在最终错误6)
    });
 

下面是完整的类。我现在有在课堂上我的的onCreate方法,这个问题的方法。 错误5'抱怨的返回类型,这一事实让我相信这之中的OnCreate中'是错误的地点显然是无效的。凡在code否则将其生产其他括号错误。

希望有人能看到我的布局错误是怎么了。

 包com.example.flybase2;

进口android.app.AlertDialog;
进口android.app.AlertDialog.Builder;
进口android.app.ListActivity;
进口android.content.DialogInterface;
进口android.content.Intent;
进口android.database.Cursor;
进口android.os.Bundle;
进口android.support.v4.widget.SimpleCursorAdapter;
进口android.text.Editable;
进口android.text.TextWatcher;
进口android.view.View;
进口android.view.View.OnClickListener;
进口android.widget.EditText;
进口android.widget.ImageButton;
进口android.widget.ListView;

公共类ViewAppointments扩展ListActivity实现OnClickListener {
SimpleCursorAdapter的CursorAdapter;
ListView控件searchedAppView;
的ImageButton searchAppoints;
的EditText searchAppName;
龙身份证;

 // @燮pressWarnings(德precation)
 // @燮pressWarnings(静态访问)


@覆盖
保护无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);


的setContentView(R.layout.appointmentview);

sea​​rchedAppView =(ListView控件)findViewById(android.R.id.list);

sea​​rchAppoints =(的ImageButton)findViewById(R.id.btnSearchAppointName);
sea​​rchAppName =(EditText上)findViewById(R.id.inputAppointName);

    DBHandlerApp DBAppointments =新DBHandlerApp(这一点,NULL,NULL);

    DBHandlerApp searchApps =新DBHandlerApp(这一点,NULL,NULL);

    sea​​rchApps.open();


    光标光标= searchApps.getAppointmentsData();
     sea​​rchApps.close();
    startManagingCursor(光标);


    字符串从=新的String [] {DBAppointments.KEY_NAMEAPP,DBAppointments.KEY_TYPEAPP,DBAppointments.KEY_TIMEAPP,DBAppointments.KEY_DATEAPP,DBAppointments.KEY_COMMENTAPP} [];
    INT []到=新INT [] {R.id.txtAppointName,R.id.txtAppointType,R.id.txtAppointTime,R.id.txtAppointDate,R.id.txtAppointCom};


    CursorAdapter的=新SimpleCursorAdapter(这一点,R.layout.setappointviews,光标,从,到);
    sea​​rchedAppView.setAdapter(CursorAdapter的);

    sea​​rchedAppView.setTextFilterEnabled(真正的);

    sea​​rchAppoints.setOnClickListener(本);

    sea​​rchAppName.addTextChangedListener(新TextWatcher()
     {

        @覆盖
        公共无效onTextChanged(CharSequence中,诠释开始,诠释之前,
                诠释计数){


        }

        @覆盖
        公共无效beforeTextChanged(CharSequence中,诠释开始,诠释计数,
                之后INT){


        }

        @覆盖
        公共无效afterTextChanged(编辑S){



                。cursorAdapter.getFilter()滤波器(s.toString());

        }

     });

            // **********错误**********
    DBHandlerApp changedAppoint =新DBHandlerApp(这一点,NULL,NULL);

     cursorAdapter.setFilterQueryProvider(FilterQueryProvider()
    {
        公共光标runQuery(CharSequence的约束)
        {
            返回changedAppoint.getChanges(constraint.toString());

        }
    });


    };


@覆盖
公共无效的onClick(查看clickedSearch)

{

    。字符串searchedName = searchAppName.getText()的toString();

    DBHandlerApp searchOnName =新DBHandlerApp(这一点,NULL,NULL);
    DBHandlerApp了getColumns =新DBHandlerApp(这一点,NULL,NULL);
    sea​​rchOnName.open();

    光标nameResult = searchOnName.searchAppByName(searchedName);

    @燮pressWarnings(静态访问)
    字符串从=新的String [] {getColumns.KEY_NAMEAPP,getColumns.KEY_TYPEAPP,getColumns.KEY_TIMEAPP,getColumns.KEY_DATEAPP,getColumns.KEY_COMMENTAPP} [];
    INT []到=新INT [] {R.id.txtAppointName,R.id.txtAppointType,R.id.txtAppointTime,R.id.txtAppointDate,R.id.txtAppointCom};

    @燮pressWarnings(德precation)

    SimpleCursorAdapter的CursorAdapter =新SimpleCursorAdapter(这一点,R.layout.setappointviews,nameResult,从,到);
    sea​​rchedAppView.setAdapter(CursorAdapter的);

}

@覆盖
保护无效onListItemClick(ListView的L,视图V,INT位置,长IDD){
    super.onListItemClick(L,V,位置,IDD);
    最后DBHandlerApp delApp =新DBHandlerApp(这一点,NULL,NULL);

    ID = IDD;

    最后的CharSequence []项目= {编辑约会详细信息,删除约会};

    构建alertDialogBu​​ilder =新AlertDialog.Builder(ViewAppointments.this);

    alertDialogBu​​ilder.setTitle(任命选项:);



    alertDialogBu​​ilder.setItems(项目,新DialogInterface.OnClickListener(){

        公共无效的onClick(DialogInterface对话,诠释项){

            如果(项目[项目] .equals(编辑约会详细信息)){

                意图的setName =新的意向书(com.example.flybase2.AppointmentEditChanges);
                setName.putExtra(passedID,身份证);
                startActivity(setname可以);

            }

            否则,如果(项目[项目] .equals(删除约会)){

                      delApp.open();
                      delApp.deleteAppointment(ID);
                      delApp.close();

            }

            }

        });

    alertDialogBu​​ilder.show();
}
 

}

解决方案
  

该方法FilterQueryProvider()是未定义的类型   ViewAppointments。

该错误是不是提供 FilterQueryProvider 的实例给 setFilterQueryProvider()方法调用一个 FilterQueryProvider()方法,它会搞乱了。相反,它应该是这样的:

  cursorAdapter.setFilterQueryProvider(新FilterQueryProvider(){

    公共光标runQuery(CharSequence的约束){
        返回changedAppoint.getChanges(constraint.toString());
    }
});
 

和使 changedAppoint 最后

 最后DBHandlerApp changedAppoint =新DBHandlerApp(这一点,NULL,NULL);
 

看你上面的更改后有任何错误。

I'm trying to filter the results of a cursor returned from my database Handler class through the use of the 'setFilterQueryProvider' on the simple cursor adapter class. At the moment I'm getting multiple errors on the following method:

Current errors:

Error 1:

The method FilterQueryProvider() is undefined for the type ViewAppointments.

Error 2:

Syntax error, insert ";" to complete Statement.

Error 3:

Illegal modifier for the variable runQuery; only final is permitted

Error 4:

Syntax error on token ")", ; expected

Error 5:

Void methods cannot return a value.

Error 6:

Syntax error on token ")", delete this token.

The above errors are noted on the following code:

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

             //ERROR 1 on 'FilterQueryProvider' and ERROR 2 on end ')'.
     cursorAdapter.setFilterQueryProvider(FilterQueryProvider()

            {

            //ERROR 3 on 'runQuery'. Error 4 on end ')'.
        public Cursor runQuery(CharSequence constraint)
        {
                //ERROR 5.
            return changedAppoint.getChanges(constraint.toString());

        }
        ERROR 6 on end ')'
    });

Here is the completed class. I currently have this problematic method in my 'onCreate' method of the class. The fact 'ERROR 5' is complaining about the return type leads me to believe this being in 'OnCreate' is the wrong place as obviously it is void. Placing it else where in the code produces other brackets errors.

Hopefully someone can see where my layout error is going wrong.

package com.example.flybase2;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.widget.SimpleCursorAdapter;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ListView;

public class ViewAppointments extends ListActivity implements OnClickListener {
SimpleCursorAdapter cursorAdapter;
ListView searchedAppView;
ImageButton searchAppoints;
EditText searchAppName;
Long id;

 //@SuppressWarnings("deprecation")
 //@SuppressWarnings("static-access")


@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());

        }

     });

            //********** ERRORS **********
    DBHandlerApp changedAppoint = new DBHandlerApp (this, null, null);

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

        }
    });


    };


@Override
public void onClick(View clickedSearch)

{

    String searchedName = searchAppName.getText().toString();

    DBHandlerApp searchOnName = new DBHandlerApp(this, null, null);
    DBHandlerApp getColumns = new DBHandlerApp(this, null, null);
    searchOnName.open();

    Cursor nameResult = searchOnName.searchAppByName(searchedName);

    @SuppressWarnings("static-access")
    String [] from = new String [] {getColumns.KEY_NAMEAPP, getColumns.KEY_TYPEAPP, getColumns.KEY_TIMEAPP, getColumns.KEY_DATEAPP, getColumns.KEY_COMMENTAPP};
    int [] to = new int [] {R.id.txtAppointName, R.id.txtAppointType, R.id.txtAppointTime, R.id.txtAppointDate, R.id.txtAppointCom};

    @SuppressWarnings("deprecation")

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

}

@Override
protected void onListItemClick(ListView l, View v, int position, long idd) {
    super.onListItemClick(l, v, position, idd);
    final DBHandlerApp delApp = new DBHandlerApp(this, null, null);

    id = idd;

    final CharSequence[] items = {"Edit Appointment Details", "Delete Appointment"};

    Builder alertDialogBuilder = new AlertDialog.Builder(ViewAppointments.this);

    alertDialogBuilder.setTitle("Appointment Options:");



    alertDialogBuilder.setItems(items, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int item) {

            if (items[item].equals("Edit Appointment Details")) {

                Intent setName = new Intent("com.example.flybase2.AppointmentEditChanges");
                setName.putExtra("passedID", id);
                startActivity(setName);

            }

            else if (items[item].equals("Delete Appointment")) {

                      delApp.open();
                      delApp.deleteAppointment(id);
                      delApp.close();

            }

            }  

        });

    alertDialogBuilder.show();
}

}

解决方案

The method FilterQueryProvider() is undefined for the type ViewAppointments.

The error is pretty self explanatory, instead of providing an instance of FilterQueryProvider to the setFilterQueryProvider() method you call a FilterQueryProvider() method which will mess things up. Instead it should be like this:

cursorAdapter.setFilterQueryProvider(new FilterQueryProvider() {

    public Cursor runQuery(CharSequence constraint) {
        return changedAppoint.getChanges(constraint.toString());
    }
});

And make changedAppoint final :

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

See if you have any errors after the changes above.

这篇关于光标s​​etFilterQueryProvider问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆