SwipeActionAdapter with StickyListHeaders

I am trying to combine these two amazing Android libraries:

https://github.com/emilsjolander/StickyListHeaders

https://github.com/wdullaer/SwipeActionAdapter

I worked with the owner of the SwipeActionAdapter, which says this is possible ( https://github.com/wdullaer/SwipeActionAdapter/issues/29 ), but I still get errors:

08-02 11:33:07.364 1655-1655/com.slaptap.tappedin E/InputEventReceiver﹕ Exception dispatching input event. 08-02 11:33:07.364 1655-1655/com.slaptap.tappedin E/MessageQueue-JNI﹕ Exception in MessageQueue callback: handleReceiveCallback 08-02 11:33:07.380 1655-1655/com.slaptap.tappedin E/MessageQueue-JNI﹕ java.lang.NullPointerException at com.wdullaer.swipeactionadapter.SwipeActionTouchListener.onTouch(SwipeActionTouchListener.java:419) at android.view.View.dispatchTouchEvent(View.java:7701) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2210) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1945) 

I have a basic adapter wrapped with a Swipe adapter. Then I have another adapter (ListStickyAdapter) that extends the Decorator adapter and implements Sticky Adapater.

  mAdapter = new ListAdapter(getActivity(), data); swipeAdapter = new SwipeActionAdapter(mAdapter); ListStickyAdapter vbsa = new ListStickyAdapter(swipeAdapter); listView.setAdapter(vbsa); // is it because of this line? (having to pass the sticky header child list) swipeAdapter.setListView(listView.getWrappedList()) 

What am I doing wrong here?

+6
source share
2 answers

Your guess seems correct, probably this line:

 swipeAdapter.setListView(listView.getWrappedList()) 

You have an error on line 419 in SwipeActionTouchListener, because there is no search group (down):

 L419 mDownViewGroup.showBackground... 

mDownViewGroup is a child view initialized with a down action:

  ... child = mListView.getChildAt(i); child.getHitRect(rect); if (rect.contains(x, y)) { try { mDownViewGroup = (SwipeViewGroup) child; ... 

I do not know the structure lying in the listview.getWrappedList () list that you provide, but I assume that for swipeaction this is not like that. If you don’t like this, probably due to the fact that the package removes the child structure (int childCount = mListView.getChildCount (); <- you get childcount = 0, mDownViewGroup is not initialized). Try to understand why a wrapped list removes a child structure, and you are likely to get what happens.

Edit: Searched a little more, it seems that this is not a fact that it does not receive children, but because it does not receive a swipeviewgroup:

 java.lang.ClassCastException: se.emilsjolander.stickylistheaders.WrapperView cannot be cast to com.wdullaer.swipeactionadapter.SwipeViewGroup 

I managed to get it to work by marking up and creating a WrapperView extends SwipeViewGroup (instead of ViewGroup). Some sensory performer also had to be protected, but there wasn’t much work. But that’s all it takes.

A working example is available here: https://github.com/he667/StickyListSwipe

+1
source

StickyListHeaders seems to use a very similar approach to SwipeActionAdapter, as it wraps the main views and possibly rewrites some touch artists to do this.

Gomoku7 is true that you will need to create a StickyListHeaders fork to make it work. Their shell should be the last because of how the library is executed, and therefore, it should know about SwipeViewGroup from below (by extension from this class), just as it should be aware that the base view can implement Checkable.

+1
source

All Articles