eJoe
eJoe

Reputation: 485

How to show context menu on long press in list view when using android-swipelistview-sample from 47deg?

I have problem with context menu when using android-swipelistview-sample from 47deg .(https://github.com/47deg/android-swipelistview). Problem is that when short click is made context menu is displayed .

How to show context menu just for long click ?

Upvotes: 0

Views: 331

Answers (2)

Stanislav Semukhyn
Stanislav Semukhyn

Reputation: 11

This bug is caused by curved touch event distribution in 47degrees swipe listview. To fix this, just comment out

view.onTouchEvent(motionEvent);

in onTouch() method, in the end of switch case MotionEvent.ACTION_DOWN: in SwipeListViewTouchListener. Issue will go away, but scrolling your ListView will become dull, as soon, as your touch events will not be recognized while the listview is scrolling. To overcome this problem, simply add to your SwipeListView class new flag, something like isScrolled. Then, you need to update this flag each time, the scrolling state changes:

mListView.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView absListView, int i) {
                mListView.setScrolling(i == SCROLL_STATE_FLING);
            }
            @Override
            public void onScroll(AbsListView absListView, int i, int i2, int i3) {

            }
        });

And finally, make it distribute touch event only when the view is scrolling:

if(swipeListView.isScrolling()){
                view.onTouchEvent(motionEvent);
            }

Good luck!

Upvotes: 1

Ashish Tamrakar
Ashish Tamrakar

Reputation: 820

I think you were implementing the code on onItemLongClick, try creating context menu public void onCreateContextMenu(final ContextMenu menu, final View v, final ContextMenuInfo menuInfo) where you will setup the menus.

Hope this helps you.

Upvotes: 0

Related Questions