0

我有一个扩展 ArrayAdapter 的类(adaptadorTemas,是 listView 的适配器)。我有另一个扩展 SQLiteOpenHelper (sqlStuff) 的类。

所以,我想从我的适配器类查询数据库,但我收到了这个错误: 构造函数 SqlStuff(AdaptadorTemas, String, null, int) is undefined

Eclipse 在我的 SQLiteOpenHelper 类中创建了一个构造函数来解决问题,但后来我得到了这个:

构造函数 SQLiteOpenHelper(AdaptadorTemas, String, Object, int) 未定义

我不明白发生了什么……请帮忙?

4

1 回答 1

1

There are two solutions here:

  1. You can add a field private Context theContext; to your custom ArrayAdapter subclass that can store a Context. Then you can pass an Activity instance or the Application Context to the constructor. From there, you can just call SqlStuff(theContext, ...) to create your SqlStuff class.
  2. You could make your ArrayAdapter subclass a private inner class of the Activity that you are using it in, defined in the same java file as that Activity. Then, you can get an instance of the outer Activity class very easily to pass to SqlStuff just with MyActivity.this. I prefer this method in my applications.
于 2013-06-18T18:32:33.897 回答