Java is case-sensitive, and it seems that you pasted the text before enclosing it between "#IF JAVA" and "#END IF", so the IDE capitalized the recognized words thinking that it was a B4A statement --> change it to "private" (lower-cased) and make sure that it hasn't happened the same with the other pasted lines.
I haven't tested the above code, but if it works (I assume so), there is still a part missing: it will need a slight modification to accept the child scrollview as a parameter, and then it will have to be called from B4A through JavaObject
Thanks JordiCP, I've re-pasted the code but still need some help.
I have got a basic JavaObject to work OK in the Main module:
#If JAVA
public String FirstMethod() {
return "Hello from Java!";
}
#End If
Sub Process_Globals
Private java_testing As JavaObject
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
java_testing.InitializeContext
End If
Dim s As String = java_testing.RunMethod("FirstMethod", Null)
Log(s) ' prints Hello from Java!
End Sub
But when I add the code for ScrollViews I get a compiler error saying that the View symbol/package is not recognised:
Compiling generated Java code. Error
javac 1.8.0_171
main.java:2701: error: cannot find symbol
private void requestDisallowParentInterceptTouchEvent(View __v, Boolean __disallowIntercept) {
^
symbol: class View
location: class main
1 error
I'm guessing that View is some kind of foundation class from which ScrollView is descended.
This is the code I have pasted in:
#If JAVA
private void makeMyScrollSmart() {
myScroll.setOnTouchListener(new View.OnTouchListener() {
@override
public boolean onTouch(View __v, MotionEvent __event) {
if (__event.getAction() == MotionEvent.ACTION_DOWN) {
// Disallow the touch request for parent scroll on touch of child view
requestDisallowParentInterceptTouchEvent(__v, true);
} else if (__event.getAction() == MotionEvent.ACTION_UP || __event.getAction() == MotionEvent.ACTION_CANCEL) {
// Re-allows parent events
requestDisallowParentInterceptTouchEvent(__v, false);
}
return false;
}
});
}
private void requestDisallowParentInterceptTouchEvent(View __v, Boolean __disallowIntercept) {
while (__v.getParent() != null && __v.getParent() instanceof View) {
if (__v.getParent() instanceof ScrollView) {
__v.getParent().requestDisallowInterceptTouchEvent(__disallowIntercept);
}
__v = (View) __v.getParent();
}
}
#End If