Giter VIP home page Giter VIP logo

pinned-section-listview's Introduction

Easy to use ListView with pinned sections for Android 2.1 and higher. Pinned section is a header view which sticks to the top of the list until at least one item of that section is visible.

Screenshot 1  Screenshot 2  Screenshot 3

Features

This list properly implements many features which are missing from other implementations. These are

  • Fast scroll
  • Headers and footers
  • Clickable pinned sections

Besides this it doesn't create any unnecessary views, layouts etc. It's really lean.

Watch this video to see PinnedSectionListView in action.

Usage example

  1. Replace standard ListView with de.halfbit.pinnedsection.PinnedSectionListView in your layout.xml file.
  <de.halfbit.pinnedsection.PinnedSectionListView
      android:id="@android:id/list"
      android:layout_width="match_parent"
      android:layout_height="wrap_content" 
      />
  1. Extend your ListAdapter in a way that it implements PinnedSectionListAdapter interface, in addition to what it already implements. Basically you need to add a single isItemViewTypePinned(int viewType) method. This method must return true for all view types which have to be pinned.
  // Our adapter class implements 'PinnedSectionListAdapter' interface
  class MyPinnedSectionListAdapter extends BaseAdapter 
          implements PinnedSectionListAdapter {
  
      ...
    
      // We implement this method to return 'true' for all view types we want to pin
      @Override
      public boolean isItemViewTypePinned(int viewType) {
          return viewType == <type to be pinned>;
      }
  }

That's all. You are done! A working example can also be found in example folder.

Use with Gradle

Add this to your module-level build.gradle:

dependencies {
    compile "de.halfbit:pinned-section-listview:1.0.0"
}

Used by

Let us know if you use this library in your application and we will mention it here.

Grocery Sum

Slack

License

Copyright 2013-2016 Sergej Shafarenka, halfbit.de

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

pinned-section-listview's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pinned-section-listview's Issues

Content adapter has changed but ListView...

This is the typical notifyDataSetChanged issue, however it works with a simple adapter, but not with the PinnedSectionList Library.
The Adapter is an ArrayAdapter
The error is being thrown at onLayout in the Library in the super call.

We are updating the dataset Items (Arraylist) from a thread and calling the main thread with notifyDataSetChanged once done. But occasionally it will FC.

null pointer at "pinnedView.measure(ws, hs);"

I had a null pointer at "pinnedView.measure(ws, hs);" (217) when using the listview in a fragment of a 2 panel version of the layout.

I fixed it by adding "pinnedView.setLayoutParams(layoutParams);" at line 203 after you created a new layoutparam when it previously returned a null layoutparam...

Custom adapter

Hi,
i have a problem when implementing custom listview adapter. I get nullPointerException and even if i manage it to work i get Exception on scroll.

ListView padding gets ignored

Thanks for the implementation!

When the ListView has padding, the pinned view still sticks to the top left of the parent on scrolling.

NullPointerException when using layoutparams without checking it in createPinnedShadow method

NullPointerException occurs when using layoutparams without checking it in createPinnedShadow method,
and I fixed it by adding the codes below:
final ViewGroup.LayoutParams vlp = pinnedView.getLayoutParams();
AbsListView.LayoutParams lp;
if (vlp == null) {
lp = (LayoutParams) generateDefaultLayoutParams();
} else if (!checkLayoutParams(vlp)) {
lp = (LayoutParams) generateLayoutParams(vlp);
} else {
lp = (LayoutParams) vlp;
}
pinnedView.setLayoutParams(lp);
BETWEEN
// request new view
View pinnedView = getAdapter().getView(position, recycleView, PinnedSectionListView.this);
AND
// read layout parameters
LayoutParams layoutParams = (LayoutParams) pinnedView.getLayoutParams();

how to remove white shadow on top

When scrolled to the top, the section will have white shadow on the top of the section, how to remove it? already tried to use setShadowVisible(false) but it still show up

how pinned listView add footView

I want add footView when the data is end , and click foot view load more data ,how will I do , is pinned list has this feature

NullPointer when scrolling down

Hi I get this when scrolling down, I dont know why:

05-13 09:36:32.138: E/AndroidRuntime(5014): FATAL EXCEPTION: main
05-13 09:36:32.138: E/AndroidRuntime(5014): java.lang.NullPointerException
05-13 09:36:32.138: E/AndroidRuntime(5014): at com.hb.views.PinnedSectionListView$1.onScroll(PinnedSectionListView.java:96)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.widget.AbsListView.invokeOnItemScrollListener(AbsListView.java:1326)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.widget.AbsListView.trackMotionScroll(AbsListView.java:5055)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.widget.AbsListView.scrollIfNeeded(AbsListView.java:3193)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.widget.AbsListView.onTouchEvent(AbsListView.java:3467)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.view.View.dispatchTouchEvent(View.java:7127)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2170)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1905)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
05-13 09:36:32.138: E/AndroidRuntime(5014): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1925)
05-13 09:36:32.138: E/AndroidRuntime(5014): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1379)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.app.Activity.dispatchTouchEvent(Activity.java:2396)
05-13 09:36:32.138: E/AndroidRuntime(5014): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1873)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.view.View.dispatchPointerEvent(View.java:7307)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3172)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3117)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4153)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4132)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4224)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:171)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:163)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:4203)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:4243)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.view.Choreographer.doFrame(Choreographer.java:523)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.os.Handler.handleCallback(Handler.java:615)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.os.Handler.dispatchMessage(Handler.java:92)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.os.Looper.loop(Looper.java:137)
05-13 09:36:32.138: E/AndroidRuntime(5014): at android.app.ActivityThread.main(ActivityThread.java:4745)
05-13 09:36:32.138: E/AndroidRuntime(5014): at java.lang.reflect.Method.invokeNative(Native Method)
05-13 09:36:32.138: E/AndroidRuntime(5014): at java.lang.reflect.Method.invoke(Method.java:511)
05-13 09:36:32.138: E/AndroidRuntime(5014): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
05-13 09:36:32.138: E/AndroidRuntime(5014): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
05-13 09:36:32.138: E/AndroidRuntime(5014): at dalvik.system.NativeStart.main(Native Method)

text gone

when use a textview with gravity center as section item in listview , text will be gone when i scroll this section up , but withou gravity center , it works fine, i want to know why?

java.lang.ClassCastException

My app got some java.lang.ClassCastException on some devices. I don't altered the code of the lib.
Errors from Google Play:

java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
at PinnedSectionListView.createPinnedShadow(PinnedSectionListView.java:201)
at  PinnedSectionListView.ensureShadowForPosition(PinnedSectionListView.java:251)
at  PinnedSectionListView$1.onScroll(PinnedSectionListView.java:116)

Errors on: Android 4.0.3 - 4.0.4, Xperia Tipo (ST21i), Xperia U (ST25i)

Section loses OnClickListener when pinned

The Section that I want to pin has an OnClickListener.

When it is not pinned at the top, the listener works. However, when it is pinned, the listener doesn't work and responds to the Listeners of the view behind the Pinned Section instead.

Class cast exception in generateDefaultLayoutParams

Hi,

I was trying to customise the PinnedListAdapter and I got ClassCastException, for line layoutParams = (LayoutParams) generateDefaultLayoutParams();
So I have changed it to
layoutParams = (AbsListView.LayoutParams) new AbsListView.LayoutParams(
AbsListView.LayoutParams.MATCH_PARENT,
AbsListView.LayoutParams.WRAP_CONTENT, 0);

And now it works fine,
Is this a bug ?

PinnedShadow is not recreated when notifyDataSet changed.

I added the data set observer in my code.

But if you change the dataset after the adpater has been attached, then the listview does not recreate the pinned view.

If you need the code I can do a pull request later.

Something like:

/**
     * Recreate the pinned view on change/invalidated.
     */
    private class AdapterDataSetObserver extends DataSetObserver{
        @Override
        public void onChanged() {
            super.onChanged();
            destroyPinnedShadow();
        }

        @Override
        public void onInvalidated() {
            super.onInvalidated();
            destroyPinnedShadow();
        }
    }

worked a charm for me

how to use pinned-section-listview with CursorAdapter

when I create my adapter extends CursorAdapter,

@OverRide
public boolean isItemViewTypePinned(int viewType) {
}
if the viewType has value must override the function
@OverRide
public int getItemViewType(int pos) {
}
and i can't get the item by cursor??
Could give a example when use pinned-section-listview with CursorAdapter??
will helper me a lot

Pinned view with fixed height

I am using a pinned view that has a fixed height of 32 dp like this:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_height="32dp"
      android:layout_width="match_parent"
      android:id="@android:id/text1"
      android:paddingLeft="16dp"
      android:paddingRight="16dp"
      android:gravity="center_vertical" />

When the view gets pinned to the top during srolling, it behaves as if it had layout_height="wrap_content", so the additional vertical space is not applied. Might be a problem with vertical padding as well.

Section item does not stay pinned

I have a list with just one list item (TextView) per section. That single list item's TextView contains wrapping text that can potentially consume the entire height of the ListView's container. If this is the case, I am finding that the pinned section item does not stay pinned, but rather it disappears only to reappear at the time the next section item is scrolled into view. To reproduce this, simply create the list with one ITEM per SECTION, and make the text for the item section very long - long enough to extend beyond the height of the ListView's container. I am observing this with the example app and have no other customization at all.

Update: To clarify, my test actually does the above, but my test list has 10 such sections, each with identical items, just for testing purposes. Again, only one item per section.

NullPointer getting layoutParams

Seems I get LayoutParams to null, but pinnedView is not null. Can we add a default layoutparams to the listview?

This is the stacktrace:

java.lang.NullPointerException
at com.hb.views.PinnedSectionListView.createPinnedShadow(PinnedSectionListView.java:164)
at com.hb.views.PinnedSectionListView.access$400(PinnedSectionListView.java:34)
at com.hb.views.PinnedSectionListView$1.onScroll(PinnedSectionListView.java:106)
at android.widget.AbsListView.invokeOnItemScrollListener(AbsListView.java:1340)
at android.widget.AbsListView.trackMotionScroll(AbsListView.java:4949)
at android.widget.AbsListView.scrollIfNeeded(AbsListView.java:3087)
at android.widget.AbsListView.startScrollIfNeeded(AbsListView.java:3032)
at android.widget.AbsListView.onTouchEvent(AbsListView.java:3357)
at android.view.View.dispatchTouchEvent(View.java:7246)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2168)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1903)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1953)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1405)
at android.app.Activity.dispatchTouchEvent(Activity.java:2410)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1901)
at android.view.View.dispatchPointerEvent(View.java:7426)
at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3220)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3165)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4292)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4271)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4363)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:179)
at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:171)
at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:4342)
at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:4382)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
at android.view.Choreographer.doCallbacks(Choreographer.java:562)
at android.view.Choreographer.doFrame(Choreographer.java:530)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.m

Bad Header when scrolling fast with FastScroll

Hi again, I also see another little issue.

If your listView implements FastScroll (your adapter must have implemented SectionIndexer) and "android:fastScrollEnabled="true" is setted for the listView, when you scroll with the fast scroll down or up very fast you can see a wrong header (ussually the last one seen).

If I dont explain well I can upload a video explaining it :)
Thanks for your work.

Compatibility ta previous Android Versions

Hello, I loved your implementation of pinned section ListView, but the problem it is that I have an HTC Desire S, which is an Adroid 2.3 powered phone. The example looked awfull in my phone, so I made some changes in your code on a separated branch, and the it could work both on my phone and on more advanced Devices, so I would Like to cooperate, pushing the branch to your project, so You Could analyze it and if you aprove, you could merge it to the master Branch!....Tell me Something!

Before the screeshots from Before and After:
2013-10-26_18-34-10
2013-10-26_19-09-24

Strange behavior sections

Hello
if i set itemsNumber=9 on 71 line then on scroll ListView last section reset previous section but not moving his

testing on Nexus S 480x800

IndexOutOfBoundsException after NotifyDataSetChanged()

After called NotifyDataSetChanged(), when recreating pinned shadow:

void recreatePinnedShadow() {
        destroyPinnedShadow();
        ListAdapter adapter = getAdapter();
        if (adapter != null && adapter.getCount() > 0) {
            int firstVisiblePosition = getFirstVisiblePosition(); // here the visible position is of the old dataset
            int sectionPosition = findCurrentSectionPosition(firstVisiblePosition);
            if (sectionPosition == -1) return; // no views to pin, exit
            ensureShadowForPosition(sectionPosition,
                    firstVisiblePosition, getLastVisiblePosition() - firstVisiblePosition);
        }
}

Looks like getFirstVisiblePosition () will return the visible position of the old dataset.

ensureShadowForPosition null pointer

I tried to filter the adapter for result.

When I scroll the list view, the ensureShadowForPosition method crash with null pointer exception as the nextSectionView is null.

I am using custom BaseAdapter with SectionIndexer and fastscroll.

My data set is an ArrayList with an object.

The object comes with listPosition and sectionPosition.

Any further information need for this issue?

scrollY not updated when padding on top is present

When there is a padding on top of listView is present, scroll is not recognized.
I modified scrollY in your QuickReturnUtils .getScrollY(AbsListView lv) as "scrollY = -(c.getTop()) + lv.getPaddingTop();". Works fine now.

Pinned sections are destroyed prematurely when a divider is specified for the PSListView, causing a jitter of the header

Because of the way ListView handles scrolling, an OnScrollListener increments firstVisibleItem as soon as a child view's getBottom() exceeds the ListView's top boundaries. Vice versa, it decrements firstVisibleItem when a child view's getBottom() is within the ListView's top boundaries.

Now consider the case of a ListView with a divider.

<PinnedSectionListView
        android:divider="@android:color/transparent"
        android:dividerHeight="8dp" />

All items other than the first item will have a spacing of 8dp above itself. However, ensureShadowForPosition() will recreate the header as soon as the positions don't match and set mTranslateY to 0, causing the newly created header to stick to the top when there should be a divider spacing, causing the header to suddenly "jump" to the top.

if section pinned view is not TextView will has show problem

I try in adapter getView return LinearLayout ,in this LinearLayout contain ImageView and TextView ,if not scroll, the section pinned item is right, but when i scroll the pinned item's TextView's text don't show , I try to changle when it is pinned Section ,when is pinned Section I return TextView and set text content, It is ok.

I hope the pinned section header can be other View not only TextView

NullPointerException

I have this while scrolling,
The previous line:
View nextSectionView = getChildAt(nextSectionPosition - firstVisibleItem);
nextSectionPosition - firstVisibleItem gives -1 so nextSectionView is null.

12-22 11:16:50.378  18806-18806/bakingcode.tweedb E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.NullPointerException
            at com.hb.views.PinnedSectionListView.ensureShadowForPosition(PinnedSectionListView.java:261)
            at com.hb.views.PinnedSectionListView$1.onScroll(PinnedSectionListView.java:122)
            at android.widget.AbsListView.invokeOnItemScrollListener(AbsListView.java:1391)
            at android.widget.AbsListView.trackMotionScroll(AbsListView.java:5399)
            at android.widget.AbsListView.scrollIfNeeded(AbsListView.java:3242)
            at android.widget.AbsListView.onTouchEvent(AbsListView.java:3690)
            at android.view.View.dispatchTouchEvent(View.java:7384)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2202)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1937)
            at com.hb.views.PinnedSectionListView.dispatchTouchEvent(PinnedSectionListView.java:466)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2208)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1951)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2208)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1951)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2208)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1951)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2208)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1951)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2208)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1951)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2208)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1951)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2208)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1951)
            at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2184)
            at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1614)
            at android.app.Activity.dispatchTouchEvent(Activity.java:2497)
            at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2132)
            at android.view.View.dispatchPointerEvent(View.java:7564)
            at android.view.ViewRootImpl$1.doDispatch(ViewRootImpl.java:354)
            at com.lge.view.TouchEventFilter.dispatchFilteredTouchEvent(TouchEventFilter.java:132)
            at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3368)
            at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3271)
            at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4501)
            at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4480)
            at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4581)
            at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:179)
            at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
            at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:171)
            at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:4551)
            at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:4600)
            at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
            at android.view.Choreographer.doCallbacks(Choreographer.java:562)
            at android.view.Choreographer.doFrame(Choreographer.java:530)
            at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
            at android.os.Handler.handleCallback(Handler.java:725)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5171)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:564)```

Filter doesn't work

I tried to implement Filterable and add a custom Filter, but the list doesn't seem to respond to the filter.

PinnedSectionListView with Overlay mode on

Has anybody managed to get this working with Overlay mode on?
The pinned section doesn't take the height of the ActionBar into account when it's scrolling to position at the top of the screen.

IndexOutOfBoundsException on deletion

When I try to delete items from the adapter, I sometimes get an IndexOutOfBoundsException, using the latest revision from github.

Here is what I had last time:

  • A class derived from ArrayListAdapter and implementing PinnedSectionListView.PinnedSectionListAdapter
  • 1 section and 3 items (section first then items)
  • a for loop that loops through all the selected items, sorted in reverse order (highest positions first as the ArrayList items get re-indexed when you remove an item)

ArrayList example:

Position Type
0 Section
1 Item 1
2 Item 2
3 Item 3

Simplified for loop:

for(int i = selectedIds.size() - 1; 0 <= i; i--){
    item = (Item)this.getItem(selectedIds.keyAt(i));
    Log.v("AlarmsListAdapter", String.format("Trying to delete item at position %d.Adapter size = %d", selectedIds.keyAt(i), this.getCount()));
    this.remove(item);
}

Logcat output:

06-09 11:24:04.740  24140-24140/com.zion.htf V/AlarmsListAdapter﹕ Trying to delete item at position 3.Adapter size = 4
06-09 11:24:04.740  24140-24140/com.zion.htf V/AlarmsListAdapter﹕ Trying to delete item at position 2.Adapter size = 3
06-09 11:24:05.030  24140-24140/com.zion.htf E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.zion.htf, PID: 24140
    java.lang.IndexOutOfBoundsException: Invalid index 2, size is 2
            at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
            at java.util.ArrayList.get(ArrayList.java:308)
            at android.widget.ArrayAdapter.getItem(ArrayAdapter.java:337)
            at com.zion.htf.adapter.AlarmsListAdapter.getItemViewType(AlarmsListAdapter.java:131)
            at com.hb.views.PinnedSectionListView.findFirstVisibleSectionPosition(PinnedSectionListView.java:282)
            at com.hb.views.PinnedSectionListView.ensureShadowForPosition(PinnedSectionListView.java:256)
            at com.hb.views.PinnedSectionListView.recreatePinnedShadow(PinnedSectionListView.java:317)
            at com.hb.views.PinnedSectionListView$2.onChanged(PinnedSectionListView.java:134)
            at android.database.DataSetObservable.notifyChanged(DataSetObservable.java:37)
            at android.widget.BaseAdapter.notifyDataSetChanged(BaseAdapter.java:50)
            at android.widget.ArrayAdapter.notifyDataSetChanged(ArrayAdapter.java:286)
            at android.widget.ArrayAdapter.remove(ArrayAdapter.java:247)
            at com.zion.htf.adapter.AlarmsListAdapter.removeSelected(AlarmsListAdapter.java:248)
            at com.zion.htf.ui.AlarmManagerActivity$1.onActionItemClicked(AlarmManagerActivity.java:70)
            at android.support.v7.internal.view.ActionModeWrapper$CallbackWrapper.onActionItemClicked(ActionModeWrapper.java:138)
            at com.android.internal.policy.impl.PhoneWindow$DecorView$ActionModeCallbackWrapper.onActionItemClicked(PhoneWindow.java:3029)
            at com.android.internal.app.ActionBarImpl$ActionModeImpl.onMenuItemSelected(ActionBarImpl.java:969)
            at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
            at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:152)
            at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
            at com.android.internal.view.menu.ActionMenuView.invokeItem(ActionMenuView.java:546)
            at com.android.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:115)
            at android.view.View.performClick(View.java:4438)
            at android.view.View$PerformClick.run(View.java:18439)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5118)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:611)
            at dalvik.system.NativeStart.main(Native Method)

When I use a ListView instead of a PinnedSectionListView, it works just fine.

multiple fixed sections

I just want to make multiple fixed sections, just like the image below. please give me a help
d7beea98-bef1-4b15-82d2-1ec9c7cd786c

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.