sergejsha / pinned-section-listview Goto Github PK
View Code? Open in Web Editor NEWEasy to use ListView with pinned sections for Android.
Easy to use ListView with pinned sections for Android.
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...
like the issue: diegocarloslima/FloatingGroupExpandableListView#26
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)
Just so would-be users don't have to hunt for it in the Manifest.
Not everyone does that, especially people new to Android. :)
BTW in DevAppsDirect, it says "4.0 or higher."
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.
When a ListView has a HeaderView or FooterView, the adapter gets wrapped in a HeaderViewListAdapter.
Would be nice if you could add an screenshot the the README.md file.
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
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.
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
Not sure how to tackle this one, so I don't have a patch (I have updated the sample on my fork that uses the header/footers), but the Sections are off by one cell. They start to scroll up and switch one cell above the next section header.
To reproduce bug just simply fast scroll down-up-down.
How to add image into pinned-section-listview. I want to show profile display in pinned-section-listview. Help me please.
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();
A null check for the adapter in findCurrentSectionPosition will fix it.
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?
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.
PinnedSectionListView pList = (PinnedSectionListView) v.findViewById(R.id.pinned_list);
pList.setOnItemClickListener( ... );
Only Section is detected and items (non-section) are not detected.
I want to Add Image with lazy list.
So,It is possible to add in it?
please help me for implement it.
How to auto scroll to pinned by index? I need implement this...
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)```
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 ?
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.
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.
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)
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
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.
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.
I find it's difficult to click child view on pinned selection.Is that any solution?it's general below android 4.0.
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
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.
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
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!
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:
ArrayListAdapter
and implementing PinnedSectionListView.PinnedSectionListAdapter
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.
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
I just downloaded and tested your project and is awesome! Congrulations for that, but i question me, it's possible add pulltorefresh to this?
Thank you :)
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
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?
How to implement setOnItemLongClickListener? I was looking for to do that!
If the list view is empty (i.e., adapter does not have any items), IndexOutOfBoundsException is thrown when rotating the device.
The below line of code returns 0, while the adapter does not have any data.
int firstVisiblePosition = getFirstVisiblePosition();
Can it use your lib via gradle? If not, could you pls support it?
I tried to implement Filterable and add a custom Filter, but the list doesn't seem to respond to the filter.
when scroll back to top and swipe the screen more the two times the list scrollback after hitting the first row on the screen
Thanks for the implementation!
When the ListView has padding, the pinned view still sticks to the top left of the parent on scrolling.
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.
It would be nice to have this library added to maven central repository or bintray's jcenter repository.
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.
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.