希望这是一个简单的,
我正在尝试在我的类中设置一个'SimpleCursorAdapter'对象变量,以便所有方法都可以访问它,所有非常标准的东西。目前我在'OnCreate'方法中出现错误,显示以下错误:
错误:
cursorAdapter cannot be resolved to a type.
继承了类中声明的SimpleCursorAdapter:
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;
DBHandlerApp delApp = new DBHandlerApp(this, null, null);
@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);
@SuppressWarnings("static-access")
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};
@SuppressWarnings("deprecation")
//ERROR: cursorAdapter cannot be resolved.
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 afterTextChanged(Editable s) {
cursorAdapter.getFilter().filter(s.toString());
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
}
});
};
答案 0 :(得分:0)
您不需要该对象。你可以这样做:
searchedAppView.getAdapter(); //listView.getAdapter()
您活动中的任何地方。
答案 1 :(得分:0)
您的问题在于注释的位置。
@SuppressWarnings("deprecation")
位于onCreate()
内,(奇怪地)导致错误。