2013-02-03 67 views
1

我想通過使用簡單遊標適配器類上的'setFilterQueryProvider'過濾從我的數據庫處理程序類返回的遊標的結果。光標setFilterQueryProvider問題

當前錯誤:

錯誤1:目前我在下面的方法越來越多的錯誤

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:

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

這裏是:

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

上述錯誤是在下面的代碼說明完成課程。我目前在這個類的'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(); 
} 

}

回答

0

方法FilterQueryProvider()是未定義的類型 ViewAppointments。

的錯誤是不言自明的,而不是到setFilterQueryProvider()方法調用一個方法FilterQueryProvider()這將胡來提供FilterQueryProvider一個實例。相反,它應該是這樣的:

cursorAdapter.setFilterQueryProvider(new FilterQueryProvider() { 

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

而且使changedAppointfinal

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

看看你上面的更改後有任何錯誤。

+0

@Luksporg。我實際上設法排除了這個錯誤。我最大的問題之一是我沒有導入filterQueryProvider小部件。它現在過濾完美。非常感謝您的反饋。 – user1352057

0

我設法解決這個問題。這是由於一些問題,但最大的問題是我沒有導入'filterQueryProvider'小部件!