无法应用todcursoradapter上下文

时间:2015-11-18 05:15:31

标签: android

我总是遇到上下文问题,此代码中存在错误,因为this

   TodoCursorAdapter todoAdapter = new TodoCursorAdapter(this, todoCursor);

我尝试添加getapplicationcontext仍然面临错误

这是班级

public class Search extends Activity {
  //  ArrayList<Contact> imageArry = new ArrayList<Contact>();
    String myJSON;

    private static final String TAG_RESULTS="result";
    private static final String TAG_ID = "id";
    private static final String TAG_NAME = "name";
    private static final String TAG_desc ="description";

    JSONArray peoples = null;

    ArrayList<HashMap<String, String>> personList;

    ListView list;
    /** Called when the activity is first created. */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.search);
        list = (ListView) findViewById(R.id.listView);
        personList = new ArrayList<HashMap<String,String>>();
        DatabaseHandler handler = new DatabaseHandler(this);
// Get access to the underlying writeable database
        SQLiteDatabase db = handler.getWritableDatabase();
// Query for items from the database and get a cursor back
        Cursor todoCursor = db.rawQuery("SELECT  * FROM OBJECTS", null);
        // Find ListView to populate
        ListView lvItems = (ListView) findViewById(R.id.lvItems);
// Setup cursor adapter using cursor from last step
       TodoCursorAdapter todoAdapter = new TodoCursorAdapter(this, todoCursor);
// Attach cursor adapter to the ListView
       // lvItems.setAdapter(todoAdapter);
    }

这是班级的构造函数

public class TodoCursorAdapter extends CursorAdapter {
        public TodoCursorAdapter(Context context, Cursor cursor, int flags) {
            super(context, cursor, 0);
        }

1 个答案:

答案 0 :(得分:1)

TodoCursorAdapter类构造函数中,它采用3个参数但当前只传递2个参数:

TodoCursorAdapter todoAdapter = new TodoCursorAdapter(Search.this, todoCursor,0);

最后一个参数值01(真/假)