Scroll a Multiline EditText in a Scrollview

Roger Garstang

Well-Known Member
Licensed User
Longtime User
Normally when you touch and move within a multiline edit view it scrolls the text, but when it is placed on a scroll view it seems to put more priority on scrolling the scroll view and maybe scrolls the Edit view a couple pixels if you are lucky.

I've read a thread on here similar to this where someone had a listview in a scrollview and it was just recommended not to do it. I have other singleline EditText views on there that I'm fine with the behavior of scrolling when they are touched and the focus changes to the top item on the screen and sometimes the keyboard opens when done scrolling, etc.

I'd just like some way to prevent the multiline EditText from passing its touch events up to the parent. Something like returning True to the Touch event (Which doesn't work in this case since it just prevents the EditText from getting focus...yet the scrollview still scrolls). There must be some way of isolating the EditText from the Scrollview as I've seen other apps that have them like this and they work.
 

Informatix

Expert
Licensed User
Longtime User
You have to stop the interception of Touch events by the ScrollView. Set a Touch listener to your EditText and try something like this:
B4X:
If Action = 2 Then '= MOVE
   If ScrollViewToBlock <> Null Then
      Dim r As Reflector
      r.Target = ScrollViewToBlock
      r.RunMethod2("requestDisallowInterceptTouchEvent", True, "java.lang.boolean")
   End If
...

I didn't try it. But I'm almost sure that's not a perfect solution in this case (the ScrollView won't scroll at all when your finger is on the EditText). Let me know.
 
Upvote 0

Roger Garstang

Well-Known Member
Licensed User
Longtime User
Searching online mentioned something like that in a couple posts, but just said to disable scrolling. I saw the InterceptTouchEvent stuff a few times in posts where people were setting scroll events, so figured there had to be a way like this to stop it. That reflection code should help out a lot.

My only problem now is it is a large screen/form with many views and uses my View Manager Class (One of the many reasons why I created it). I only pass the panel of the scrollview to the class and never do anything with the scrollview itself in it, so will have to see how that will work. All my views and their events are within the class. I did make a method to get the view in the class, so I can get the EditText view from my Activity and do what is needed in the Activity assuming B4A allows events in two places and that Reflection will have the event called in the Activity and not the class. I really wish B4A had a way to GetParent.
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
I did make a method to get the view in the class, so I can get the EditText view from my Activity and do what is needed in the Activity assuming B4A allows events in two places and that Reflection will have the event called in the Activity and not the class. I really wish B4A had a way to GetParent.

I'm sure you know how to get the Parent with the Reflection lib. ;-)

I don't see a way to listen to the same event in two different modules. Until now, I pass the event (or a flag) to another module myself.
 
Upvote 0
Top