Android Question How to findNext with runmethod2 in webview?

watesoft

Active Member
Licensed User
Longtime User
B4X:
Sub Activity_Click
   FindAll(WebView1, "Basic4android")
End Sub

Sub FindAll (w As WebView, s As String) As Int
   Dim r As Reflector
   r.Target = w
   Return r.RunMethod2("findAll", s, "java.lang.String")
End Sub

I load a long html text in webview ,find and highlight all the keyword with above code, I want to see them one by one,but when I use below code,error occurred:"NoSuchMethodException: findNext [class java.lang.String]", Where is my fault?


B4X:
Sub FindNext_Click
    FindNext(WebView1, "Basic4android")
End Sub

Sub FindNext (w As WebView, s As String) As Int
   Dim r As Reflector
   r.Target = w
   Return r.RunMethod2("findNext", s, "java.lang.String")
End Sub
 

watesoft

Active Member
Licensed User
Longtime User
Try this:
1. Find all:
B4X:
Dim jo As JavaObject = WebView1
jo.RunMethod("findAllAsync", Array(s))
2. Next match:
B4X:
Dim jo As JavaObject = WebView1
jo.RunMethod("findNext", Array(True))

Requires Android 4.1+ (api 16)

Thank you Erel,I tried the method you provided, the result is very good.
 
Upvote 0

watesoft

Active Member
Licensed User
Longtime User
Try this:
1. Find all:
B4X:
Dim jo As JavaObject = WebView1
jo.RunMethod("findAllAsync", Array(s))
2. Next match:
B4X:
Dim jo As JavaObject = WebView1
jo.RunMethod("findNext", Array(True))

Requires Android 4.1+ (api 16)

Hi Erel, I met another problem,I want to match and highlight multi keywords in webview,like below:
B4X:
Dim SS() as string
SS = Array As String("AAA", "BBB", "CCC")
Dim i as Int
Dim jo As JavaObject = WebView1
for i=0 to SS.length-1
     jo.RunMethod("findAllAsync", Array(SS(i)))
next

Result: only "CCC" is highlighted, why, I want to highlight "AAA" and "BBB" and "CCC".
 
Upvote 0

bernardR

Member
Licensed User
Hello, I have try the code of Erel (#5, Feb 9, 2018) for match and highlight multi keywords in webview.
It don't works. Only "CCC" is highlighted.
Did you find a solution ?
Thanks
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

hayk

Member
Try this:
1. Find all:
B4X:
Dim jo As JavaObject = WebView1
jo.RunMethod("findAllAsync", Array(s))
2. Next match:
B4X:
Dim jo As JavaObject = WebView1
jo.RunMethod("findNext", Array(True))

Requires Android 4.1+ (api 16)
When online PDF file is opened in webview, search matched text is not highlighted. Is there way to fix that?
 
Upvote 0
Top