Android Question WEBVIEW CLICK EVENT

manuaaa

Member
Licensed User
Longtime User
Hi all,

iam using a webview to fetch sql data using 'Executehtml2' function od Dbutils..
details are given below:-

1) first i started an activity named DBWebView on a Button click event

B4X:
Sub DrListBtn_Click
StartActivity("DBWebView")
x = 0
End Sub

2) then on DBWebView Activity :
B4X:
Sub Globals
Dim wbwTable As WebView
Dim Back As Button
   
    Dim Spinner1 As Spinner
    Dim Search As Button
    Dim RptTeamSpn As Spinner
    Dim empid As EditText
    Dim emplvl As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("WebReport")
    RptTeamSpn.SetLayout (0%x, 0%y, 80%x, 10%y)
    Search.SetLayout (80%x, 0%y, 20%x, 10%y)
    wbwTable.SetLayout(0%x, 10%y, 100%x, 88%y)
    Back.SetLayout (0%x, 88%y, 25%x, 10%y)
    DBUtils.ExecuteSpinner(Main.SQL1, "select NAME from TAB_TEAM ORDER BY NAME", Null, 0, RptTeamSpn)
End Sub

Sub ShowTableInWebView
If emplvl.Text = "" Then
Msgbox("Select Name Properly", "")
Return
End If
If emplvl.Text = 0 Then
Msgbox("Higher level Data Cannot be shown", "")
Return
End If
Dim txt As String
   
    'txt = "select [DR], [DRID] FROM " & Main.DBTableName &" "& "where [EID]=" & Main.empid
    Dim x As Int
    x= Main.x
    Select x
        Case 0
            txt = "select DISTINCT [DR], [DRID], [EID] FROM " & Main.DBTableName &" "& "where [EID]=" & empid.Text
            wbwTable.LoadHtml(DBUtils.ExecuteHtml2(Main.SQL1, txt, Null, 0, True, 16 * Scale.GetScaleX))
        Case 1     
            txt = "select [HOSPNAME], [area], [EID] FROM " & Main.DBTableName1 &" "& "where [EID]=" & empid.Text
            wbwTable.LoadHtml(DBUtils.ExecuteHtml2(Main.SQL1, txt, Null, 0, True, 16 * Scale.GetScaleX))
        Case 2     
            txt = "select [area], [AID] FROM " & Main.DBTABLENAME3 &" "& "where [EID]=" & empid.Text
            wbwTable.LoadHtml(DBUtils.ExecuteHtml2(Main.SQL1, txt, Null, 0, True, 16 * Scale.GetScaleX))
           
    End Select
    wbwTable.LoadHtml(DBUtils.ExecuteHtml2(Main.SQL1, txt, Null, 0, True, 16 * Scale.GetScaleX))
End Sub

Sub Back_Click
Activity.Finish
StartActivity("main")
End Sub
Sub Search_Click
    ShowTableInWebView
End Sub
Sub RptTeamSpn_ItemClick (Position As Int, Value As Object)
    Dim kk As Cursor
    kk = Main.SQL1.ExecQuery ("Select EID from tab_team where [Name]='" & RptTeamSpn.SelectedItem  &"'")
    For i =0 To kk.RowCount -1
    kk.Position = i
    empid.Text = kk.GetString ("EID")
      Next
    Dim k1 As Cursor
    k1 = Main.SQL1.ExecQuery ("Select ID from tab_team where [Name]='" & RptTeamSpn.SelectedItem  &"'")
    For i =0 To k1.RowCount -1
    k1.Position = i
    emplvl.Text = k1.GetString ("ID")
      Next
End Sub

Now iam using ExecuteHTML2 function of DBUtils to show sql data (related to doctors with id) in a HTML table format in a webview and it is already working but i want to show another webview if i click any row of existing webview to show the details of that Dr. from another table whose id = webview1 dr id.... how
 

klaus

Expert
Licensed User
Longtime User
You can use this routine, it comes from the DBUtils demo program you find in DBUtils - Android databases are now simple!.
B4X:
Sub WebView1_OverrideUrl (Url As String) As Boolean
    'parse the row and column numbers from the URL
    Dim values() As String
    values = Regex.Split("[.]", Url.SubString(7))
    Dim col, row As Int
    col = values(0)
    row = values(1)
    ToastMessageShow("User pressed on column: " & col & " and row: " & row, False)
    Return True 'Don't try to navigate to this URL
End Sub
 
Upvote 0
Top