Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7867651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:45:40+00:00 2026-06-03T00:45:40+00:00

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

  • 0

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 ?

EDIT:
my custom adapter extends CursorAdapter and overrides BindView and NewView

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
if (v == footer) {
    ...
} else {
        Cursor c = ((CursorAdapter) l.getAdapter()).getCursor();
        c.moveToPosition(position); 
        ...
    }
}

class PostAdapter extends CursorAdapter {

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

    @Override
    public void bindView(View view, Context context, Cursor cursor) {
        // DISPLAY DATA in view
                    ...
    }

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        LayoutInflater inflater = LayoutInflater.from(context);
        return inflater.inflate(R.layout.postrow, parent, false);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T00:45:41+00:00Added an answer on June 3, 2026 at 12:45 am

    Well from the looks of the error it doesn’t seem to agree that your HeaderViewListAdapter can be casted to a CursorAdapter.

    Why don’t you show us some of the code for your HeaderViewListAdapter?

    Edit: It appears that becuase you have headers/footers in your ListView, the adapter you get back is a HeadListViewAdapter, which wraps your original adapter.

    From Android Dev API:

    HeaderViewListAdapter
    
    ListAdapter used when a ListView has header views. This ListAdapter wraps another one and also keeps track of the header views and their associated data objects. 
    

    http://developer.android.com/reference/android/widget/HeaderViewListAdapter.html

    The following is all educated guesses, but try it out:

    1. l.getAdapter <– HeaderListViewAdapter

    2. ((HeaderListViewAdapter)l.getAdapter).getWrappedAdapter() <– The custom adapter you created.

    So instead of this: Cursor c = ((CursorAdapter) l.getAdapter()).getCursor();

    Try this:

    HeaderViewListAdapter hlva = (HeaderViewListAdapter)l.getAdapter();
    PostAdapter postAdapter = (PostAdapter)hlva.getWrappedAdapter();
    Cursor cur = postAdapter.getCursor();
    

    I broke it up so that if it doesn’t work, you’ll know exactly which statement is erroring out.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListView with a custom list adapter (that extends BaseAdapter). My list
I have a ListView with a custom Adapter that extends ArrayAdapter. It's a ArrayAdapter
i have a ListView for which i have made a custom adapter which extends
I have ListView with custom Adapter which supplies View to ListView in this way:
I have a listview with a custom adapter. Each listview item has an ImageView.
I have a listview connected to a custom array adapter. This list shows information
I have a ListView which contains custom rows. This custom row has following UI
I have a listview with custom array adapter, the view allows the user to
I have used a custom array adapter to populate my list view.The problem i
I'm trying to delete items from a ListView using a custom adapter which extends

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.