开发者

Temporary bypassing ListView scrolling

开发者 https://www.devze.com 2023-02-03 14:22 出处:网络
I\'ve got a ListActivity that displays WebViews. There is a menu option to copy text that will call this on visible WebViews.

I've got a ListActivity that displays WebViews.

There is a menu option to copy text that will call this on visible WebViews.

Everything works except for one thing. 开发者_开发技巧I can't perform text selection in vertical direction as ListView consumes corresponding MotionEvents for it's own scrolling.

I've tried this:

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    if (webViewsInTextSelectionMode) {
        bypassEventToWebViews(ev);
        return true;
    } else {
        return super.dispatchTouchEvent(ev);
    }
}

Which will block scrolling but will also pass unadjusted MotionEvent coordinates to a WebView.

Is there a way to correctly prevent ListView from scrolling in this case?


I've got a ListActivity that displays WebViews.

That is not a good idea. WebView and ListView will compete for motion events. Putting scrolling things in scrolling things is rarely advisable in Android, particularly when they can scroll in the same direction (in this case, up and down).

There is a menu option to copy text that will call this on visible WebViews.

If you mean the accepted answer on that question, that is also not a good idea. I am dubious about the other answer, but at least it's not a bad idea prima facia.

Everything works except for one thing. I can't perform text selection in vertical direction as ListView consumes corresponding MotionEvents for it's own scrolling.

My point exactly.

Is there a way to correctly prevent ListView from scrolling in this case?

I would focus instead on getting rid of the WebViews, replacing them with TextView and Html.fromHtml(). Or, get rid of the ListView, using a single WebView to render your consolidated content.


This is a complete shot in the dark and most likely won't work but probably worth a try. You can try calling ViewParent#requestDisallowInterceptTouchEvent on the parent ListView inside of the ViewGroup containing your WebView. You'll have to call that every time there is a down motion event for the duration of the text selection. This is because the flag is reset on a up/cancel motion event.

If that doesn't work you'll probably have to create your own copy of ListView and modify it appropriately. This isn't too daunting, you'll have to copy all classes in the class hierarchy back to AdapterView and fix the copied AdapterView class (mainly use of private/package level member variables that have protected/public accessors functions).

0

精彩评论

暂无评论...
验证码 换一张
取 消