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

Erel

Administrator
Staff member
Licensed User
Why is the project named Erel? This is not needed. This is a community forum. All members can help you.
 

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?
 

Erel

Administrator
Staff member
Licensed 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
 
Top