jimismith / pinnedheaderlistview Goto Github PK
View Code? Open in Web Editor NEWA ListView with pinned section headers for Android
A ListView with pinned section headers for Android
Hello ,
First thanks for your library i loved it ๐
second i want to implement pull to refresh class to your library but sections and positions not correct..
can you help me with this issue
thanks ..
I need to change the text of the pinned header when user clicks on an item. Suppose, user clicks on the first item, I need to show "1" in the pinned header, when user clicks on 2nd item on any group (means, items under that header), I need to show "2" in the pinned header.
My question is how can I get/access the header from an item's onClickListener? Is there any way like getHeaderViewByPosition(int section_position) ... or anything like this?
When a section view is pinned at the top of screen, it becomes the pinned section view, any touch events like click, swipe will be passed to the item views behind it. But when a section view is not pinned, any click events can be listened. So do you have any idea to intercept click events occurred on a pinned section view?
When I add a header to the ListView
by code e.g:
PinnedHeaderListView listView = (PinnedHeaderListView) view.findViewById(R.id.pinnedListView); LinearLayout header1 = (LinearLayout) inflater.inflate(R.layout.menu_left_header_profile, null); listView.addHeaderView(header1);
the position / section in onSectionClick/onItemClick
is invalid....
In PinnedHeaderListView.OnItemClickListener
you do not take into account the numbers of headers added to the ListView
rawPosition
in public void onItemClick(AdapterView<?> adapterView, View view, int rawPosition, long id)
contains the number of rows and headers.
I fix it by add line:
rawPosition -= ((ListView) adapterView).getHeaderViewsCount();
in:
public static abstract class OnItemClickListener implements AdapterView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int rawPosition, long id) {
SectionedBaseAdapter adapter;
if (adapterView.getAdapter().getClass().equals(HeaderViewListAdapter.class)) {
HeaderViewListAdapter wrapperAdapter = (HeaderViewListAdapter) adapterView.getAdapter();
adapter = (SectionedBaseAdapter) wrapperAdapter.getWrappedAdapter();
} else {
adapter = (SectionedBaseAdapter) adapterView.getAdapter();
}
rawPosition -= ((ListView) adapterView).getHeaderViewsCount();
int section = adapter.getSectionForPosition(rawPosition);
int position = adapter.getPositionInSectionForPosition(rawPosition);
if (position == -1) {
onSectionClick(adapterView, view, section, id);
} else {
onItemClick(adapterView, view, section, position, id);
}
}
public abstract void onItemClick(AdapterView<?> adapterView, View view, int section, int position, long id);
public abstract void onSectionClick(AdapterView<?> adapterView, View view, int section, long id);
}
When first used showing data.
And do some operations, when I need to refresh datas, calling notifyDataSetChanged(), NullPointerException thrown.
I saw the log, getItemId(int section, int position) the parameter position's value is -1.
Hi, why the section can't clickable when it scroll to top? Please help me.
hi,
i can't add view for list view, like this :
mListView.addFooter(layout);
the error :
java.lang.ClassCastException: android.widget.HeaderViewListAdapter cannot be cast to za.co.immedia.pinnedheaderlistview.SectionedBaseAdapter
please check this and fix it
My situation is like this: I placed a button inside one section header. It was clickable when there are no items behind that section header. But to my surprise, when I was scrolling down the ListView and there were section items behind the section header, the items got focus instead of the header. This is abnormal as one might expect. Is there any means to circumvent this behavior? Please be kind to reply me because there's a deadline on my project.
hi JimiSmith,
I'm using your PinnedHeaderListView class and it works well, but when I add a headerview it doesn't work what i want, the header view which I added is replaced by a blank section header view. below is my sectionadapter class code, and what should I do. thanks.
public View getItemView(int section, int position, View convertView, ViewGroup parent) {
ItemViewHolder holder = null;
if (convertView == null) {
holder = new ItemViewHolder();
convertView = (LinearLayout) this.mInflater.inflate(R.layout.view_add_friend_item, null);
holder.headimg = (ImageView)convertView.findViewById(R.id.iv_addfriend_avater);
holder.nickname = (TextView)convertView.findViewById(R.id.tv_addfriend_friend_name);
holder.desc = (TextView)convertView.findViewById(R.id.tv_addfriend_friend_des);
holder.addbtn = (Button)convertView.findViewById(R.id.bt_addfriend_add);
convertView.setTag(holder);
} else {
holder = (ItemViewHolder) convertView.getTag();
}
UserSection currentSection = sectionList.get(section);
List<UserInfo> userList = currentSection.getUserList();
UserInfo currentUser = userList.get(position);
holder.nickname.setText(currentUser.getName());
Utils.setPortrait(this.mContext, currentUser.getHeaderS(), holder.headimg);
return convertView;
}
@Override
public View getSectionHeaderView(int section, View convertView, ViewGroup parent) {
HeaderViewHolder holder = null;
if (convertView == null) {
holder = new HeaderViewHolder();
LayoutInflater inflator = (LayoutInflater)parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = (LinearLayout) inflator.inflate(R.layout.item_section_adapter_header, null);
holder.title = (TextView)convertView.findViewById(R.id.tv_section_title);
convertView.setTag(holder);
} else {
holder = (HeaderViewHolder) convertView.getTag();
}
UserSection currentSection = sectionList.get(section);
holder.title.setText(currentSection.getSectionTitle());
return convertView;
}
Does this work with expandable listview?
Hello,
I'm using your amazing PinnedHeaderListView for my project, and I encountered this issue: when scrolling, item are displayed behind the pinned header, which is what I expects, but if I click on the header, then the item behind is selected. I wnat this to have no effect.
Do you have the same behavior on your project?
I've added this in my SectionedBaseAdapter class to avoid selection of header:
@OverRide
public boolean isEnabled(int position) {
return !isSectionHeader(position);
}
But even without this function the issue is observed.
Moreover, I observed a secondary issue (but less critical for my project): The first header is not clickable. That is onSectionClick function is never called for him. I've not investigated this issue.
After having looking for a solution without success, I ask for an idea here.
Any way thank you for sharing your component.
bma
First thanks for your library.I'm using it.
My Issues:
I want to use this library to realize partial refresh(A single item to refresh,including SectionHeader and ListView's Item).
I use listview's "getChildAt(int index)" return is a SectionHeaderView.(My English is not very good, forgive me!(^__^))
How make?
My situation is like this: I placed a button inside one section header. It was clickable when there are no items behind that section header. But to my surprise, when I was scrolling down the ListView and there were section items behind the section header, the items got focus instead of the header. This is abnormal as one might expect. Is there any means to circumvent this behavior? Please be kind to reply me because there's a deadline of my project.
a little bug !
add this in onItemClick
rawPosition = rawPosition -getHeaderViewsCount();
if(rawPosition<0)return;
I tried to track positions for section and item, so I added codes below into your sample project:
listView.setOnItemClickListener(new PinnedHeaderListView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int section, int position, long id) {
Toast.makeText(MainActivity.this, "onItemClick: Section: " + section + " Position: " + position, Toast.LENGTH_SHORT).show();
}
@Override
public void onSectionClick(AdapterView<?> adapterView, View view, int section, long id) {
Toast.makeText(MainActivity.this, "onSectionClick: Section: " + section, Toast.LENGTH_SHORT).show();
}
});
But, all toasted messages imply the section
and position
are wrong. For example,
So I reckoned codes
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int rawPosition, long id) {
SectionedBaseAdapter adapter;
if (adapterView.getAdapter().getClass().equals(HeaderViewListAdapter.class)) {
HeaderViewListAdapter wrapperAdapter = (HeaderViewListAdapter) adapterView.getAdapter();
adapter = (SectionedBaseAdapter) wrapperAdapter.getWrappedAdapter();
} else {
adapter = (SectionedBaseAdapter) adapterView.getAdapter();
}
int section = adapter.getSectionForPosition(rawPosition);
int position = adapter.getPositionInSectionForPosition(rawPosition);
if (position == -1) {
onSectionClick(adapterView, view, section, id);
} else {
onItemClick(adapterView, view, section, position, id);
}
}
may be not accurate, which is from OnItemClickListener implements AdapterView.OnItemClickListener
.
So could you fix it?
I have, for example, a view of 10000dp which I use for ITEMS and 1dp for SECTION and it makes a height = wrap_content view.
Hi jimi,
when setTag in getView function and return it from activity return null ?! can check what happend .
sorry i don't have log just null pointer exception ..
Hi Jimi Smith,
First of all, I really would like to thank you for creating such a great library. Although I had looked into several tutorials to do my own implementation, none of them meet my requirement.
Till I found your libraries. It really saves me from few days of works. Once again, thank you so much! One thing I like about the library is that, it takes care of different convert views.
Making the library generic like ArrayAdapter would be great. But so far, I can live without it :)
When scrolling slowly downward (and the new section header moves upward), the newly pinned header flickers out / disappears for a split second showing the old pinned header that it replaced. It quickly flickers back in and is correctly presented. This isn't noticeable generally when scrolling fast.
As the title descibres, the event simply does not trigger for the first section header.
Is it possible to modify the code, to make it look like the current contacts-app, like on Lollipop?
I'm talking about this:
http://stackoverflow.com/q/27621425/878126
From time to time, Google will release an updated version of android-support-v4.jar. I was wondering, is it safe for me, to just simply replace the old PinnedHeaderListView-master\library\libs\android-support-v4.jar with the latest?
Thanks.
Any provision to make collapse and expand list items when header is clicked.
Hi,
I implemented this library in my project and i recieve a lot (!) of error reports all like this:
Stack trace: java.lang.NullPointerException
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:578)
at android.view.View.measure(View.java:16831)
at PinnedHeaderListView.ensurePinnedHeaderLayout(PinnedHeaderListView.java:138)
at PinnedHeaderListView.getSectionHeaderView(PinnedHeaderListView.java:121)
at PinnedHeaderListView.onScroll(PinnedHeaderListView.java:85)
at android.widget.AbsListView.invokeOnItemScrollListener(AbsListView.java:1757)
at android.widget.ListView.layoutChildren(ListView.java:1774)
at android.widget.AbsListView.onLayout(AbsListView.java:2447)
at android.view.View.layout(View.java:15204)
at android.view.ViewGroup.layout(ViewGroup.java:4793)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1076)
at android.view.View.layout(View.java:15204)
at android.view.ViewGroup.layout(ViewGroup.java:4793)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:15204)
at android.view.ViewGroup.layout(ViewGroup.java:4793)
at android.support.v7.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:502)
at android.view.View.layout(View.java:15204)
at android.view.ViewGroup.layout(ViewGroup.java:4793)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:15204)
at android.view.ViewGroup.layout(ViewGroup.java:4793)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1677)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1531)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1440)
at android.view.View.layout(View.java:15204)
at android.view.ViewGroup.layout(ViewGroup.java:4793)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1677)
at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1666)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1442)
at android.view.View.layout(View.java:15204)
at android.view.ViewGroup.layout(ViewGroup.java:4793)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1677)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1531)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1440)
at android.view.View.layout(View.java:15204)
at android.view.ViewGroup.layout(ViewGroup.java:4793)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:15204)
at android.view.ViewGroup.layout(ViewGroup.java:4793)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:15204)
at android.view.ViewGroup.layout(ViewGroup.java:4793)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2260)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2007)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1249)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6364)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:791)
at android.view.Choreographer.doCallbacks(Choreographer.java:591)
at android.view.Choreographer.doFrame(Choreographer.java:561)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:777)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5419)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
at dalvik.system.NativeStart.main(Native Method)
I can't figure it out. It never happened to me.
Is this a library bug? Is this a problem of mine?
Any hints where it can be?
Thanks!
If we have different item counts for each sections, then how to alter the adapter as shown in the sample?Right now, the different sections should have equal number of items to work, like shown in your sample.
Thanks!
https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html
SwipeRefreshLayout does not work with control. Very laggy scrolling... Issue is in how SwipeRefreshLayout calculates is it possible to scroll or not. It extracts first element from adapter and try to base own logic on it height/width/position....
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.