gpt4 book ai didi

java - 从所有方法访问 SimpleCursorAdapter

转载 作者:行者123 更新时间:2023-11-29 09:06:36 26 4
gpt4 key购买 nike

我试图在我的类中设置一个“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) {

}

});

};

最佳答案

您的问题与注释的位置有关。

@SuppressWarnings("deprecation")

onCreate() 中,这(奇怪地)导致了错误。

关于java - 从所有方法访问 SimpleCursorAdapter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14676385/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com