Android Question OPENING WEBVIEW BY CLICKING HTML TABLE CELL DATA

manuaaa

Member
Licensed User
Longtime User
Hi all,

B4X:
Sub ExecuteHtml2(SQL As SQL, Query As String, StringArgs() As String, Limit As Int, Clickable As Boolean, TextSize As Int) As String
    Dim Table As List
    Dim cur As Cursor
    Dim HtmlCSS2 As String

    HtmlCSS2 = "table {width: 100%;border: 1px solid #cef;text-align: left;counter-reset: serial-number; }" _
    & "td:first-child:before {counter-increment: serial-number;content: counter(serial-number); font-size:" & TextSize & "px; }" _
    & " th { font-size:" & TextSize & "px; font-weight: bold;    background-color: #acf;    border-bottom: 1px solid #cef; }" _
    & "td,th {    padding: 4px 5px; }" _
    & ".odd {background-color: #def; } .odd td {border-bottom: 1px solid #cef; }" _
    & "a { font-size:" & TextSize & "px; text-decoration:none; color: #000;}"

    If StringArgs <> Null Then
        cur = SQL.ExecQuery2(Query, StringArgs)
    Else
        cur = SQL.ExecQuery(Query)
    End If
    If Limit > 0 Then Limit = Min(Limit, cur.RowCount) Else Limit = cur.RowCount
    Dim sb As StringBuilder
    Log("ExecuteHtml: " & Query)
    sb.Initialize
    sb.Append("<html><body>").Append(CRLF)
    sb.Append("<style type='text/css'>").Append(HtmlCSS2).Append("</style>").Append(CRLF)
    sb.Append("<table><tr>").Append(CRLF)
    sb.Append("<th>SL</th>")
    For i = 0 To cur.ColumnCount - 1
        sb.Append("<th>").Append(cur.GetColumnName(i)).Append("</th>")
    Next

    sb.Append("</tr>").Append(CRLF)
    For row = 0 To Limit - 1
        cur.Position = row
        If row Mod 2 = 0 Then
            sb.Append("<tr>")
        Else
            sb.Append("<tr class='odd'>")
        End If
        sb.Append("<td></td>")
        For i = 0 To cur.ColumnCount - 1
            sb.Append("<td>")

                sb.Append("<a href='http://www.manwin.in/dr.asp")
                sb.Append("'>").Append(cur.GetString2(i)).Append("</a>")
                    
            sb.Append("</td>")
        Next
        sb.Append("</tr>").Append(CRLF)
    Next
    cur.Close
    sb.Append("</table></body></html>")
    Return sb.ToString
End Sub


I think everybody knows about executehtml2 function. Fuction details are given above.
i use this function to view sql table data in html table format with help of webview and its working fine for me. and also through this iam calling an asp page at click of each cell. and this is also works fine for me.

Now i dont want to call that data from web via asp page.

I needs to know is it possible to start another activity with a webview by clicking any cell's Data or html table data of present webview?

i mean to say that at present it is :

activity with webview >>>>>> to>>>>>>cell data with html page link

now i need:

Clicking Cell Data >>>>>>> to >>>>>> activity with webview link

need help ..............!!!!! pls


Thanks & regards
Manoj Kumar
 
Last edited:

eurojam

Well-Known Member
Licensed User
Longtime User
you can use the OverrideUrl to catch the click event on an URL and then load a new activity
 
Upvote 0

eurojam

Well-Known Member
Licensed User
Longtime User
it should be something like this:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    wv.Initialize("wv")
    Activity.AddView(wv,0,0,100%x,100%y)

    Dim html = $"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
    <title>Untitled</title>
</head>
<table> <tr> <td><a href="Activity_B">Activity B</a></td> </tr> </table>
</body>
</html>"$

wv.LoadHtml(html)

End Sub
Sub wv_OverrideUrl (Url As String) As Boolean
   
    Log (Url)
   
    If Url.Contains("Activity_B") Then
      StartActivity(B)

    End If
    Return True
End Sub
 
Upvote 0

manuaaa

Member
Licensed User
Longtime User
one more problem iam facing ....

as you know with the help of executeHTML2 function iam calling my sql data in a html tabel format on given webview..
this table shows 5 columns . first 3 of them contains data and the rest 2 were id's.

i don't want to show those column which contains id's (i mean 4th and 5th column) in webview but i need them because on the bases of those id's iam calling the next webview with data.

how can i hide those columns?

is there any way ?
 
Upvote 0

manuaaa

Member
Licensed User
Longtime User
how can i get the selected rows 3rd or 4th cells value via webview_override function...or any other method?
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
In the SQLiteLight4 example in the User's Guide there is something similar.
I read the table in a webview and read the rowids separately in a List.
The principle is the same for your problem.
You find the examples also here: SQLiteLight four simple SQLite projects
 
Last edited:
Upvote 0

manuaaa

Member
Licensed User
Longtime User
the example is no more available....

How can i change the url structure to include the content together with the index.
while analysing for the same i came to know that it is done through executememorytable function.
it help us to get the values from opened html table on a webview.

but i didn't know how to do it. actually my first webview with data is opening successfully but when i click on any particular row of that table i am unable to get the values of each cell of that row. actually there are 5 cells in a row i need the value of selected rows 3rd and 4th value. these cells conains ID 's of a master table data.

on the basis of these id's i want to open another webview with master data on the click event of first webview.

with the help of webview_override function iam able to open second webview. but the data is blank.. i don't know how to get it.... please help

details are given below:

Main Activity Details

B4X:
Sub Process_Globals
Public DBTABLENAME = "TAB_DR_EMP_MAP" As String
Public DBTABLENAME6 = "Dr_Brand" As String
Dim x as Int
Dim SQL1 As SQL
end sub

Sub Globals
    Dim DrListBtn As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    If File.Exists(File.DirDefaultExternal,"amritham.sql") = False Then
        File.Copy(File.DirAssets,"amritham.sql",File.DirDefaultExternal, "amritham.sql")
   
End If
end sub

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


DBWebView Activity Details


B4X:
Sub Globals
Dim wbwTable As WebView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("WebReport"
ShowTableInWebView
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
    Dim x As Int
    x= Main.x
    Select x
        Case 0
            txt = "select [DR], [HOSPNAME], [AREANAME], [EID], [DRID], [HID] FROM " & Main.DBTableName &" "& "where [EID]=" & empid.Text
            wbwTable.LoadHtml(DBUtils.ExecuteHtml2(Main.SQL1, txt, Null, 0, True, 10 * Scale.GetScaleX))
       
        Case 1     
            txt = "select DISTINCT [HOSPNAME], [AREANAME], [EID], [HID] FROM " & Main.DBTableName &" "& "where [EID]=" & empid.Text
            wbwTable.LoadHtml(DBUtils.ExecuteHtml3(Main.SQL1, txt, Null, 0, True, 10 * Scale.GetScaleX))
            'xs=1
        Case 2     
            txt = "select DISTINCT [AREANAME], [EID], [AID] FROM " & Main.DBTableName &" "& "where [EID]=" & empid.Text
            wbwTable.LoadHtml(DBUtils.ExecuteHtml4(Main.SQL1, txt, Null, 0, True, 10 * Scale.GetScaleX))
       
    End Select
End Sub

Sub wbwTable_OverrideUrl (Url As String) As Boolean
  Dim values() As String

    Log (Url)
    If Url.Contains("Activity_A") Then
      StartActivity(DBWebView2)
      xs =0
    End If
End Sub

DBUtils.ExecuteHTML2 Functions Details:


B4X:
Sub Process_Globals
   Dim DB_REAL, DB_INTEGER, DB_BLOB, DB_TEXT As String
   Dim qq As Int
   Dim dd As Int
   Dim hh As Int
   DB_REAL = "REAL"
   DB_INTEGER = "INTEGER"
   DB_BLOB = "BLOB"
   DB_TEXT = "TEXT"
   Dim HtmlCSS As String
   HtmlCSS = "table {width: 100%;border: 1px solid #cef;text-align: left; }" _
     & " th { font-weight: bold;   background-color: #acf;   border-bottom: 1px solid #cef; }" _
     & "td,th {   padding: 4px 5px; }" _
     & ".odd {background-color: #def; } .odd td {border-bottom: 1px solid #cef; }" _
     & "a { text-decoration:none; color: #000;}"
End Sub


Sub ExecuteHtml2(SQL As SQL, Query As String, StringArgs() As String, Limit As Int, Clickable As Boolean, TextSize As Int) As String
    Dim Table As List
    Dim cur As Cursor
    Dim HtmlCSS2 As String
    
    
    HtmlCSS2 = "table {width: 100%;border: 1px solid #cef;text-align: left;counter-reset: serial-number; }" _
    & "td:first-child:before {counter-increment: serial-number;content: counter(serial-number); font-size:" & TextSize & "px; }" _
    & " th { font-size:" & TextSize & "px; font-weight: bold;    background-color: #acf;    border-bottom: 1px solid #cef; }" _
    & "td,th {    padding: 4px 5px; }" _
    & ".odd {background-color: #def; } .odd td {border-bottom: 1px solid #cef; }" _
    & "a { font-size:" & TextSize & "px; text-decoration:none; color: #000;}"

    If StringArgs <> Null Then
        cur = SQL.ExecQuery2(Query, StringArgs)
    Else
        cur = SQL.ExecQuery(Query)
    End If
    If Limit > 0 Then Limit = Min(Limit, cur.RowCount) Else Limit = cur.RowCount
    Dim sb As StringBuilder
    Log("ExecuteHtml: " & Query)
    sb.Initialize
    sb.Append("<html><body>").Append(CRLF)
    sb.Append("<style type='text/css'>").Append(HtmlCSS2).Append("</style>").Append(CRLF)
    sb.Append("<table><tr>").Append(CRLF)
    sb.Append("<th>SL</th>")
    For i = 0 To cur.ColumnCount - 1
        sb.Append("<th>").Append(cur.GetColumnName(i)).Append("</th>")
    Next
   
    sb.Append("</tr>").Append(CRLF)
    For row = 0 To Limit - 1
        cur.Position = row
        If row Mod 2 = 0 Then
            sb.Append("<tr>")
        Else
            sb.Append("<tr class='odd'>")
        End If
        sb.Append("<td></td>")
        For i = 0 To cur.ColumnCount - 1
            sb.Append("<td>")
                sb.Append("<a href='Activity_A")
                sb.Append("'>").Append(cur.GetString2(i)).Append("</a>")
            sb.Append("</td>")
        Next
        sb.Append("</tr>").Append(CRLF)
    Next
    cur.Close
    sb.Append("</table></body></html>")
    Return sb.ToString
   
End Sub

by this i am able to view the data in 1st webview and when i click on any particular row wbwTable_OverrideUrl function opens a second activity named DBWebView2 for me.

DBWebView2 Activity Details

B4X:
Sub Process_Globals
Dim xt As Int
End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("WebReport2")
ShowTableInWebView2
End Sub

Sub ShowTableInWebView2
Dim txt1 As String
   
    xt= DBWebView.xs
    Select xt
        Case 0
               txt1 = "select [BRAND] from " & Main.DBTableName6 &" "& "where [EID]=" & dbutils.qq & " " & "AND DRID=" & dbutils.dd
            wbwTable2.LoadHtml(DBUtils.ExecuteHtml7(Main.SQL1, txt1, Null, 0, True, 10 * Scale.GetScaleX))
    End Select
   
End Sub

I need Value of 3rd column [EID] in Variable 'DBUtils.qq' and Value of 4th Column [DRID] in Variable 'DBUtils.dd'
this is my problem.. I Dont know How to get it .... While analysing for the same i found that it can get from Webview_Override Function & ExecuteMemoryTable function but didn't get the way to do it..

Is there Anybody to help...!!
 
Upvote 0

manuaaa

Member
Licensed User
Longtime User
i had an html page sample source code.. Below mentioned are the details:
B4X:
<html>
    <head>
    <script type="text/javascript">
    function myFun(e){
    if(!e.target)
        alert(e.srcElement.innerHTML);
    else
        alert(e.target.innerHTML);
    }
    </script>
    </head>
    <body>
    <table id="tableID" onclick="myFun(event)" border="1">
    <tr>
    <td>100</td>
    <td>101</td>
    </tr>
    <tr>
    <td>102</td>
    <td>103</td>
    </tr>
    </table>
    </body>
    </html>

In this example when we clicked any cell an alert occurs in a popup with the cell value.

thats all i need

is that possible to include java script in executehtml function like above?
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Tried but Didn't worked for me...
What did you try and how !?
Without knowing what exactly you have done and how it's impossible to give concrete advices.
You should post a small example showing the problem so we could see what you have done and give a complete answer.
 
Upvote 0
Top