I'm trying to fill a listview with a database query. I'm using a custom adapter that extends cursor adapter. I don't know what constructor to use. When i use the default one:
public AdapterListview(Context context, Cursor c) {
super(context, c);
// TODO Auto-generated constructor stub
}
It works fine, but i'm getting a warning that is deprecated. I did some research and it looks like it is recommended to use the following and use 0 for the flags.
public AdapterListview(Context context, Cursor c, int flags) {
super(context, c, flags);
// TODO Auto-generated constructor stub
}
But it looks like it is not supported for anything under API 11, and my project is targetting API 8. Nevertheless I tried it anyway and i get the following logcat error:
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)
So i feel at a loss for what i'm supposed to do.
The CursorAdapter from Support Library v4 has the (Contex, Cursor, int)
constructor. Set up the project to use the library and in your code replace import CursorAdapter;
with import android.support.v4.widget.CursorAdapter;
.