Android Question findAll in webview

GERSON PINTO

Member
Licensed User
Hello!
Attached is a simple project that load a webpage in a webview and using the findAll RunMethod2 search and highlight all words searched. It's ok!
Why Log(FindAll(WebView1, word)) always return 0?
I need count the number of occurrences the word found..
How I can do this?
What is wrong in the code?
Any tips?
 

Attachments

  • findall.zip
    9.3 KB · Views: 315

GERSON PINTO

Member
Licensed User
Sorry Erel! I forgot to rename the project before posting. I will correct this.... My doubt is addressed to the whole community. Can you help anyway?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You must use findAllAsync with a listener:
B4X:
Sub Globals
   Private btnFind As Button
   Private EditText1 As EditText
   Private WebView1 As WebView
   Private FindListener As Object
End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   Activity.LoadLayout("webfind")
   WebView1.LoadUrl("http://www.planalto.gov.br/ccivil_03/Constituicao/ConstituicaoCompilado.htm")
   Dim jo As JavaObject = WebView1
   FindListener = jo.CreateEventFromUI("android.webkit.WebView.FindListener", "FindListener", Null)
   jo.RunMethod("setFindListener", Array(FindListener))
End Sub

Sub btnFind_Click
   Dim word As String = EditText1.Text
   Dim jo As JavaObject = WebView1
   jo.RunMethod("findAllAsync", Array(word))
   Do While True
       Wait For FindListener_Event (MethodName As String, Args() As Object)
       Dim ActiveMatchOrdinal As Int = Args(0) 'ignore
       Dim NumberOfMatches As Int = Args(1)
       Dim IsDoneCounting As Boolean = Args(2)
       If IsDoneCounting Then Exit
   Loop
   Log("Total matches: " & NumberOfMatches)
End Sub
 
Upvote 0
Top