1. *** New version of B4J is available ***
    B4J v7.8
    Dismiss Notice

Android Question findAll in webview

Discussion in 'Android Questions' started by GERSON PINTO, May 1, 2019.

  1. GERSON PINTO

    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?
     

    Attached Files:

  2. Erel

    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 likes this.
  3. GERSON PINTO

    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?
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    You must use findAllAsync with a listener:
    Code:
    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
     
    BillMeyer and GERSON PINTO like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice