CallSub(subName As String, callUIThread As boolean, parameter1 As String, parameter2 As String)
The callUIThread parameter is an important update - it's not available with JSInterface.
Does the Sub called by your javascript modify your activity UI?
If the answer is yes then you need to pass boolean true as callUIThread otherwise you can pass false.
If you pass false and then the Sub tries to modify your activity UI you will get an exception.
Does your javascript require a return value from your Sub?
If the answer is yes then the Sub MUST NOT modify the activity UI.
If CallSub is excuted with callUIThread set to true then no values will be returned from your Sub to the javascript.
You will need to structure your B4A code so that Subs that return values to javascript do not modify the activity UI.
Code for HTML Table
<!-- an example link from column 4, row 1 of your table --><td><a href="javascript:void(0)" onclick="B4A.CallSub('CellClickHandler', '4', '1')">08:02 PM</a></td>
<td><a href="javascript:void(0)" onclick="B4A.CallSub('CellClickHandler', false, '4', '1')">08:02 PM</a></td>
<td><a href="javascript:void(0)" onclick="B4A.CallSub('CellClickHandler', true, '4', '1')">08:02 PM</a></td>
<style type="text/css">
a {
text-decoration:none;
}
</style>
<style type="text/css">
a {
color:black; /* or whatever color you want */
text-decoration:none;
}
</style>
Here is the entire code for one of my activities.
------------------ END Quote ------------------------
Ricky D states in his Post that he is using Android 2.3.6 and WebViewExtras B4A.CallSub does NOT work.
I have the same problem: Using Galaxy Tab 7 updated to Android 2.3.6 and WebViewExtras B4A.CallSub does NOT work.
Have tried a 100 things... it will never work.
WebViewExtras B4A.CallSub is my preferred tool... warwound... what is the solution?
You did not reply to Ricky D.... no solution yet?
Urgently need B4A.CallSub !!
Sub ExecuteHtml(Limit As Int) As String
If Limit > 0 Then Limit = Min(Limit, listAddMenuItems.Size) Else Limit = listAddMenuItems.Size
Dim sb As StringBuilder
sb.Initialize
sb.Append("<html><body>").Append(CRLF)
sb.Append("<style type='text/css'>").Append(HtmlCSS).Append("</style>").Append(CRLF)
sb.Append("<table><tr>").Append(CRLF)
'Create the header line
For i = 0 To 1
Select i
Case 0 'Id
sb.Append("<th>").Append("Id").Append("</th>")
Case 1 'MenuItem
sb.Append("<th>").Append("Menu Item").Append("</th>")
End Select
Next
sb.Append("</tr>").Append(CRLF)
'Create the rows
For row = 0 To Limit - 1
Dim Record() As String
Record = listAddMenuItems.Get(row)
If row Mod 2 = 0 Then
sb.Append("<tr>")
Else
sb.Append("<tr class='odd'>")
End If
For i = 0 To Record.Length - 1
sb.Append("<td>")
sb.Append(u.BuildHTMLField(row, i, Record(i)))
'sb.Append("<a href='http://").Append(i).Append(".")
'sb.Append(row)
'sb.Append(".com'>").Append(Record(i)).Append("</a>")
sb.Append("</td>")
Next
sb.Append("</tr>").Append(CRLF)
Next
sb.Append("</table></body></html>")
Log(sb.ToString)
Return sb.ToString
End Sub
Sub BuildHTMLField(row As Int, col As Int, value As String) As String
Dim sb As StringBuilder
sb.Initialize
sb.Append("<a href=" & QUOTE & "javascript:void(0)" & QUOTE).Append("onclick=" & QUOTE & "B4A.CallSub('CellClickHandler', true, " & row & "," & col).Append(")").Append(QUOTE)
sb.Append(">").Append(value).Append("</a>")
Return sb.ToString
End Sub
Sub CellClickHandler(RowStr As String, ColStr As String)
Dim Row, Col As Int
Row = RowStr
Col= ColStr
Dim TableID As Int
Dim Record() As String
Record = listAddMenuItems.Get(Row)
TableID = Record(0)
Dim result As Int
result = Msgbox2("You have selected Add Menu Item " & Record(1),"Choose","Edit","Delete","Cancel",Null)
Dim s As String
Select result
Case DialogResponse.POSITIVE
addmenuitem.Initialize(Record(0), Record(1), False)
StartActivity(AddMenuEdit)
Case DialogResponse.CANCEL
result = Msgbox2("Are you sure you want to Delete Menu Item " & Record(1) & "?","Confirm Delete","Yes","","No",Null)
If result = DialogResponse.POSITIVE Then
s = "DELETE FROM AddMenuItems WHERE Id=" & TableID
u.mySQL.ExecNonQuery(s)
LoadAddMenuItems
End If
End Select
End Sub
Ricky D states in his Post that he is using Android 2.3.6 and WebViewExtras B4A.CallSub does NOT work.
I have the same problem: Using Galaxy Tab 7 updated to Android 2.3.6 and WebViewExtras B4A.CallSub does NOT work.
Have tried a 100 things... it will never work.
WebViewExtras B4A.CallSub is my preferred tool... warwound... what is the solution?
You did not reply to Ricky D.... no solution yet?
Urgently need B4A.CallSub !!
Javascript = "B4A.CallSub('HTMLsub', true, document.documentElement.outerHTML)"
The forum won't allow me to post the code - the javascript in the code is detected by the forum as malicious!
See attached files.
Wow, thank you very much! This really helps me a lot.
I tried your zip and it works excellent.
May I ask you for one more favour: What code should I add to automatically press the "Zoeken" button on that webpage?
Thank you in advance.
Javascript.Append("document.forms.masterform.submit()")
document.forms.user-login.name.value='my_email_address@email.com';
document.forms['user-login'].name.value='my_email_address@email.com';
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?