Hi,
I think this is my first time post
My english are not good enaugh and I sorry for this.
I'm about to get webpage Title with this code
B4X:
Sub Globals
Private WebView1 As WebView
Private WebViewExtras1 As WebViewExtras
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout")
WebView1.Initialize("WebView1")
WebViewExtras1.Initialize(WebView1)
WebViewExtras1.JavaScriptEnabled = True
WebView1.LoadUrl("https://www.youtube.com/")
End Sub
Sub WebView1_PageFinished (Url As String)
Log("PageFinished: "&Url)
WebViewExtras1.ExecuteJavascript("document.title")
End Sub
Sub Button1_Click
MsgboxAsync(WebViewExtras1.GetTitle, "Website Title Is")
End Sub
This code above is success
I have list of urls form SQLite database and load them to ListView
Sub Button2_Click
If File.Exists(File.DirInternal, "webpage.db") = True Then
SQL.Initialize(File.DirInternal, "webpage.db", False)
Cursor = SQL.ExecQuery("SELECT url FROM urls_table")
For i = 0 To Cursor.RowCount - 1
Cursor.Position = i
ListView1.AddSingleLine2(Cursor.GetString("url"), i)
Next
Else
MsgboxAsync("Can't open database", "")
Return
End If
End Sub
How to check all this list urls using WebView1.LoadUrl and them back to ListView1.AddTwoLines ?
Like this
Not sure you can populate the same ListView with SingleLine and then TwoLines, but it's been a while.....
Are you using a pre-defined DB list? i.e. it just contains URLs? Ideally you would store the Title alongside the URL and use the query to populate the ListView.AddTwoLines instead of AddSingleLine2.
Ideally you need to get the item selected, to populate the correct entry in ListView, although xCustomListView is recommended instead of ListView.
You need to define ListView with with either two Lines from the first call - even if you've only got one piece of information. either set the title to null or blank text then populate it by a press or long press as you've done above - but you will need the index of the item selected in the ListView so that you just update that one.
Thank you Erel
I use ListView to simplyfy and I just need two string which is Title and URL.
For the SQL, I put the code on button click to test if code work or not.
Yes I want to get the title of each url but I do know how to do that automatically?
I just check it one by one
Not sure you can populate the same ListView with SingleLine and then TwoLines, but it's been a while.....
Are you using a pre-defined DB list? i.e. it just contains URLs? Ideally you would store the Title alongside the URL and use the query to populate the ListView.AddTwoLines instead of AddSingleLine2.
Ideally you need to get the item selected, to populate the correct entry in ListView, although xCustomListView is recommended instead of ListView.
You need to define ListView with with either two Lines from the first call - even if you've only got one piece of information. either set the title to null or blank text then populate it by a press or long press as you've done above - but you will need the index of the item selected in the ListView so that you just update that one.
My DB have only contains two fields 'nomor' and 'urls'. I just need to populate urls to string or may be array of string but I don know. So far I could do is check it one by one on click event or long click event. Here is my code
B4X:
Dim Nomor As Int
Nomor = Position + 1
SQL.Initialize(File.DirInternal, "webpage.db", False)
Cursor = SQL.ExecQuery("SELECT url FROM urls_table WHERE nomor LIKE '%"&Nomor&"%'")
Cursor.Position = 0
WebView1.LoadUrl((Cursor.GetString("url"))
MsgboxAsync(WebViewExtras1.GetTitle, "Website Title Is")
Cursor.Close
Personally I'd be storing it in the DB once I'd grabbed it. Possibly checking to see if it exists in the DB and grabbing if not. Maybe even updating it once it's a few weeks or months old as well. Otherwise it means you are grabbing the title every time someone accesses the list view. Which feels wrong - what happens when you don't have connectivity?