【问题标题】:extending cursorAdapter, what constructor to use扩展 cursorAdapter,使用什么构造函数
【发布时间】:2012-10-27 02:26:39
【问题描述】:

我正在尝试使用数据库查询填充列表视图。我正在使用扩展光标适配器的自定义适配器。我不知道使用什么构造函数。当我使用默认的:

public AdapterListview(Context context, Cursor c) {
    super(context, c);
    // TODO Auto-generated constructor stub
}

它工作正常,但我收到一个已弃用的警告。我做了一些研究,看起来建议使用以下内容并使用 0 作为标志。

public AdapterListview(Context context, Cursor c, int flags) {
    super(context, c, flags);
    // TODO Auto-generated constructor stub
}

但它似乎不受 API 11 下的任何东西的支持,而且我的项目以 API 8 为目标。尽管如此,我还是尝试了它,但出现以下 logcat 错误:

10-27 02:11:22.230: E/AndroidRuntime(491): FATAL EXCEPTION: main
10-27 02:11:22.230: E/AndroidRuntime(491): java.lang.NoSuchMethodError: android.widget.CursorAdapter.<init>
10-27 02:11:22.230: E/AndroidRuntime(491):  at com.mangodeveloper.mcathomie.AdapterListview.<init>(AdapterListview.java:14)
10-27 02:11:22.230: E/AndroidRuntime(491):  at com.mangodeveloper.mcathomie.ActivityStats.onCreate(ActivityStats.java:36)
10-27 02:11:22.230: E/AndroidRuntime(491):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-27 02:11:22.230: E/AndroidRuntime(491):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
10-27 02:11:22.230: E/AndroidRuntime(491):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
10-27 02:11:22.230: E/AndroidRuntime(491):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
10-27 02:11:22.230: E/AndroidRuntime(491):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
10-27 02:11:22.230: E/AndroidRuntime(491):  at android.os.Handler.dispatchMessage(Handler.java:99)
10-27 02:11:22.230: E/AndroidRuntime(491):  at android.os.Looper.loop(Looper.java:123)
10-27 02:11:22.230: E/AndroidRuntime(491):  at android.app.ActivityThread.main(ActivityThread.java:3683)
10-27 02:11:22.230: E/AndroidRuntime(491):  at java.lang.reflect.Method.invokeNative(Native Method)
10-27 02:11:22.230: E/AndroidRuntime(491):  at java.lang.reflect.Method.invoke(Method.java:507)
10-27 02:11:22.230: E/AndroidRuntime(491):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-27 02:11:22.230: E/AndroidRuntime(491):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-27 02:11:22.230: E/AndroidRuntime(491):  at dalvik.system.NativeStart.main(Native Method)

所以我对我应该做的事情感到茫然。

【问题讨论】:

  • 支持库 v4 包括 CursorAdapter。您可以使用support library中的那个

标签: android android-listview android-cursoradapter android-cursor


【解决方案1】:

Support Library v4 的 CursorAdapter 具有 (Contex, Cursor, int) 构造函数。设置项目以使用该库并在您的代码中将 import CursorAdapter; 替换为 import android.support.v4.widget.CursorAdapter;

【讨论】:

  • 完全有效。我一直有这个库,但我想它永远不会出现,因为我没有将它添加到构建路径中。
猜你喜欢
  • 2013-11-15
  • 2012-01-09
  • 2021-02-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-22
相关资源
最近更新 更多