Wednesday, May 2, 2012

ClassCastException on getCursor() of a CursorAdapter when the ListView has a footer

I have a ListView with a custom adapter that extends CursorAdapter.
that ListView also has a footer view



when a list item is clicked (which is not the footer) in the OnListItemClickListener
I get a ClassCastException on



Cursor c = ((CursorAdapter)l.getAdapter()).getCursor();

E/AndroidRuntime( 8579): FATAL EXCEPTION: main
E/AndroidRuntime( 8579): java.lang.ClassCastException: android.widget.HeaderViewListAdapter
E/AndroidRuntime( 8579): at com.gbenhaim.dealsapp.BrowsePostsActivity.onListItemClick(BrowsePostsActivity.java:277)
E/AndroidRuntime( 8579): at android.app.ListActivity$2.onItemClick(ListActivity.java:319)
E/AndroidRuntime( 8579): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
E/AndroidRuntime( 8579): at android.widget.ListView.performItemClick(ListView.java:3513)
E/AndroidRuntime( 8579): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1812)
E/AndroidRuntime( 8579): at android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime( 8579): at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 8579): at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime( 8579): at android.app.ActivityThread.main(ActivityThread.java:3683)
E/AndroidRuntime( 8579): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 8579): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 8579): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime( 8579): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime( 8579): at dalvik.system.NativeStart.main(Native Method)


the footer view is inflated and added to the listview before setting the adapter.



clicking on the footer works fine and
if I don't add the footer to the listview clicking on a list item works fine



what is the problem and how do i fix it ?





No comments:

Post a Comment