Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different type of view for the Sticky header section, other than normal header. How to do that? #128

Closed
venkyg88 opened this issue Jun 29, 2016 · 3 comments
Labels

Comments

@venkyg88
Copy link

venkyg88 commented Jun 29, 2016

I had tried sub classing the Flexible Adapter and Implementing the getStickySectionHeadersHolder , Inside these method i had inflated a Layout , and returning the view group which is present in that view.

But view is null and throws exception,

Process: com.bt.bms, PID: 26259
java.lang.NullPointerException: Attempt to write to field 'int android.view.ViewGroup$LayoutParams.width' on a null object reference
at eu.davidea.flexibleadapter.helpers.StickyHeaderHelper.ensureHeaderParent(StickyHeaderHelper.java:208)
at eu.davidea.flexibleadapter.helpers.StickyHeaderHelper.swapHeader(StickyHeaderHelper.java:200)
at eu.davidea.flexibleadapter.helpers.StickyHeaderHelper.updateHeader(StickyHeaderHelper.java:149)
veu.davidea.flexibleadapter.helpers.StickyHeaderHelper.updateOrClearHeader(StickyHeaderHelper.java:137)
veu.davidea.flexibleadapter.helpers.StickyHeaderHelper.initStickyHeadersHolder(StickyHeaderHelper.java:116)
at eu.davidea.flexibleadapter.helpers.StickyHeaderHelper.access$000(StickyHeaderHelper.java:40)
at eu.davidea.flexibleadapter.helpers.StickyHeaderHelper$1.run(StickyHeaderHelper.java:78)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
@davideas
Copy link
Owner

@venkyg88, in a recent fix I had to add a new parameter for the FlexibleViewHolder Constructor, did you pass true?

I will have to replicate your case later today when i will be at home.
If you have more details, please give them to me.

However, did you try to use the XML layout instead to inflate yours?

@venkyg88
Copy link
Author

@davideas yes, i am passing true to that FlexibleViewHolder Constructor and i used XML layout also . with these it works fine. but my requirement is to have a separate view[layout] for sticky header and other view[layout] for normal headers . Can you help me in achieving these requirement ?

@davideas
Copy link
Owner

davideas commented Jun 29, 2016

@venkyg88, if you use xml layout, you can still have different header types with same layout representation.
So you want display headers with a different layout representation when sticky?

I've tested that the line in NPE is because params object is null, so you have to initialize the view group with layout params before returning the ViewGroup. It's not properly a bug because you need to provide this info anyway.
However, I will add a check for the params to be initialized correctly.

ViewGroup.LayoutParams params = mStickyHolderLayout.getLayoutParams(); //params is null!!
params.width = view.getMeasuredWidth(); //view is ok!

Done the initialization, I think, you then need to attach the layout to its parent (addChild as last view in the layout), the parent can be the activity, otherwise as I just tested the header is not shown because StickyHolderLayout not laid out.

If you want, because I didn't experiment too much on this customization, you can try and see if it works, then would you like to add a short description of how to achieve it programmatically? I gave you the indications already.
Thanks!

@davideas davideas changed the title I am using FlexibleAdapter with Sticky Header. My requirement is to have a different type of view for the Sticky header section, other than normal header. How to do that ? Different type of view for the Sticky header section, other than normal header. How to do that? Jun 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants