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 8248083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:04:38+00:00 2026-06-07T23:04:38+00:00

Anyone know how to properly add a HeaderView to a ListView in android? This

  • 0

Anyone know how to properly add a HeaderView to a ListView in android? This is what I have:

LayoutInflater inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View inflatedView = inflater.inflate(R.layout.adapter_post_note, commentsListView, false);

after that I setup an ImageView and a couple TextView’s that are already part of the adapter_post_note layout by setting the image resource and/or text. then here is where I add the HeaderView

commentsListView.addHeaderView(inflatedView);
commentsAdapter = new CommentsAdapter(this, post.getComments(), post);
commentsListView.setAdapter(commentsAdapter);

The adapter is a custom adapter that extends BaseAdapter and I pass in the context, the List that populates the ListView, and the “post” for some reason, but it doesnt matter.

here is the error i am getting

07-16 12:39:58.858: E/AndroidRuntime(1562): FATAL EXCEPTION: main
07-16 12:39:58.858: E/AndroidRuntime(1562): java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams
07-16 12:39:58.858: E/AndroidRuntime(1562):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:360)
07-16 12:39:58.858: E/AndroidRuntime(1562):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
07-16 12:39:58.858: E/AndroidRuntime(1562):     at android.view.View.measure(View.java:8372)
07-16 12:39:58.858: E/AndroidRuntime(1562):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
07-16 12:39:58.858: E/AndroidRuntime(1562):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
07-16 12:39:58.858: E/AndroidRuntime(1562):     at android.view.View.measure(View.java:8372)
07-16 12:39:58.858: E/AndroidRuntime(1562):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
07-16 12:39:58.858: E/AndroidRuntime(1562):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
07-16 12:39:58.858: E/AndroidRuntime(1562):     at android.view.View.measure(View.java:8372)
07-16 12:39:58.858: E/AndroidRuntime(1562):     at android.view.ViewRoot.performTraversals(ViewRoot.java:844)
07-16 12:39:58.858: E/AndroidRuntime(1562):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1868)
07-16 12:39:58.858: E/AndroidRuntime(1562):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-16 12:39:58.858: E/AndroidRuntime(1562):     at android.os.Looper.loop(Looper.java:130)
07-16 12:39:58.858: E/AndroidRuntime(1562):     at android.app.ActivityThread.main(ActivityThread.java:3701)
07-16 12:39:58.858: E/AndroidRuntime(1562):     at java.lang.reflect.Method.invokeNative(Native Method)
07-16 12:39:58.858: E/AndroidRuntime(1562):     at java.lang.reflect.Method.invoke(Method.java:507)
07-16 12:39:58.858: E/AndroidRuntime(1562):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
07-16 12:39:58.858: E/AndroidRuntime(1562):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
07-16 12:39:58.858: E/AndroidRuntime(1562):     at dalvik.system.NativeStart.main(Native Method)

I have tried setting the layout params of inflatedView to ListView.LayoutParams, FrameLayout.LayoutParams, AbsListView.LayoutParams, nothing works. It seems to me as if it is adding the inflatedView as the header just fine, but then later on when it attempts to invalidate the screen, it tries to go through and recycle ListView children states and it fails, that just a guess, but any thoughts?

Also, one more thing I have tried is

View.inflate(this, R.layout.adapter_post_note, null);

but it still doesnt work

  • 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-07T23:04:39+00:00Added an answer on June 7, 2026 at 11:04 pm

    Set the parent view to null and you are good to go. No need to reference the parent of the view. Just inflate it and pass it to the method.

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

Sidebar

Related Questions

Anyone know an example of phonegap with $.ajax() in github for Android? I have
I'm getting a Object doesn't support this property or method error, does anyone know
Anyone know how to do draw sth similar to this in Java and working
Does anyone know why this is, or how to fix it? I'm using an
Does anyone know how to set the TextBox.Width property to fill up the remainder
Does anyone know how to bind a Yes/No radio button to a boolean property
Does anyone know how to dump environment name in log4net? e.g. <conversionPattern value=%date{ISO8601} Server:%property{log4net:HostName}
Anyone know how I can make a login button in Ruby on Rails for
Anyone know how to set the custom 404 Error pages that the Visual Studio
Anyone know if there is a standard way to create a List from an

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.