0

I am getting following exception while adding header to listview on the line channellist.addHeaderView(header);-

java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams

I have tried both-

View header = View.inflate(getActivity(), R.layout.headerchannel, null);

and

View header = inflater.inflate(R.layout.headerchannel, null,false);

but same exception I am getting. My HomeActivity do have a framelayout and it is required for my project.

3 Answers 3

1

if u see:

java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams

u must do this:

header.setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));

before channellist.addHeaderView(header);

Sign up to request clarification or add additional context in comments.

2 Comments

then try change in header.xml RelativeLayout to FrameLayout
have u listview and header in one xml? why u used android:layout_below="@+id/header"
0

You should use

View header = inflater.inflate(R.layout.headerchannel, null);

1 Comment

@BhuvneshVarma oh, can you try this View header = inflater.inflate(R.layout.headerchannel, channellist, false);?
0

I think in your header your root element is RelativeLayout. Which is ViewGroup not View. So Inflate it in a ViewGroup.

That's the reason it gives you ClassCastException. You are trying to convert ViewGroup intp View.

So first of all check that your layout is ViewGroup or View. If it's viewgroup you have to do this ..

ViewGroup header = LayoutInflater.from(getActivity()).inflate(R.layout.headerchannel, null);

Or it's just a view then..

View header = LayoutInflater.from(getActivity()).inflate(R.layout.headerchannel, null);

2 Comments

have you tried ViewGroup or LayoutInflater.from()..?
remove false parameter from this line View header = inflater.inflate(R.layout.headerchannel, null,false); like this View header = inflater.inflate(R.layout.headerchannel, null); and try

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.