mathew-kurian/TextJustify-Android

How to enable longClick functionality?

Closed this issue · 3 comments

I need my DocumentView to be handle long click by user. I tried to set in xml

android:longClickable="true"

and

docView.setLongClickable(true);

Still no result. OnTouchListener works fine. Am I missing something?

So, DocumentView is extending ScrollView which also doesn't catch onLongClockListener. But. there is the workaround which works fine

GestureDetector.OnGestureListener gestureOnDocListener = new GestureDetector.SimpleOnGestureListener()
{
    @Override
    public void onLongPress(MotionEvent e)
    {
        Toast.makeText(getActivity(), "LongClick", Toast.LENGTH_SHORT).show();
    }
};

...

 @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        setRetainInstance(true);
...
final GestureDetector gestureDetector = new GestureDetector(getActivity(), gestureOnDocListener);
documentView.setOnTouchListener(new View.OnTouchListener()
{
    @Override
    public boolean onTouch(View v, MotionEvent event)
    {
        return gestureDetector.onTouchEvent(event);
    }
});

If you can make a PR and a test case, I will be happy to merge it.

I'll make PR this weekend