1

我试图通过在简单游标适配器类上使用“setFilterQueryProvider”来过滤从我的数据库处理程序类返回的游标的结果。目前,我在以下方法中遇到多个错误:

当前错误:

错误一:

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

错误2:

Syntax error, insert ";" to complete Statement.

错误 3:

Illegal modifier for the variable runQuery; only final is permitted

错误 4:

Syntax error on token ")", ; expected

错误 5:

Void methods cannot return a value.

错误6:

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

上述错误在以下代码中注明:

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 ')'
    });

这是完成的课程。我目前在类的“onCreate”方法中有这个有问题的方法。'ERROR 5' 抱怨返回类型的事实让我相信这在 'OnCreate' 中是错误的地方,因为它显然是无效的。将它放在代码中的其他位置会产生其他括号错误。

希望有人能看到我的布局错误在哪里出错。

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

}

4

2 回答 2

0

我设法解决了这个问题。这是由于许多问题,但最大的问题是我没有导入“filterQueryProvider”小部件!

于 2013-02-04T21:09:33.243 回答
0

对于 ViewAppointments 类型,未定义方法 FilterQueryProvider()。

该错误很容易解释,而不是为您调用的方法提供一个实例,FilterQueryProvidersetFilterQueryProvider()会使FilterQueryProvider()事情变得混乱。相反,它应该是这样的:

cursorAdapter.setFilterQueryProvider(new FilterQueryProvider() {

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

并制作changedAppoint final

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

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

于 2013-02-04T20:06:47.247 回答