Android Question Question ABout listview

victormedranop

Well-Known Member
Licensed User
Longtime User
hI, There a way to display the content that is going down a httpjob in a listview before this is over?
I have this code to read the content of the data downloaded.

B4X:
Sub [B]JobDone[/B] (Job As HttpJob)
Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
If Job.Success = True Then
Select Job.JobName
Case "Job1"
Log("JOB 1")
Dim parser As JSONParser
parser.Initialize(Job.GetString)
Dim root As List = parser.NextArray
For Each colroot As Map In root
Dim date As String = colroot.Get("date")
Dim thumb_url As String = colroot.Get("thumb_url")
Dim video_url As String = colroot.Get("video_url")
Dim author As String = colroot.Get("author")
Dim audio_url As String = colroot.Get("audio_url")
Dim title As String = colroot.Get("title")
List1.Add(date)
List2.add(trim_string2(thumb_url))
Log(trim_string2(thumb_url))
List3.Add(video_url)
List4.Add(RemoveAccents(author))
List5.Add(audio_url)
List6.Add(trim_string(title))
Log(trim_string(title))
ListView1.AddTwoLinesAndBitmap( trim_string(title),trim_string(title),LoadBitmapSample(File.DirAssets,"play2.png",15dip,15dip))
Next
' For x = 1 To List1.Size -1
' ListView1.AddTwoLinesAndBitmap( List6.Get(x),List4.Get(x),LoadBitmapSample(File.DirAssets,"play2.png",15dip,15dip))
' Next
End Select
Else
Log("Error: " & Job.ErrorMessage)
ToastMessageShow("Error: " & Job.ErrorMessage, True)
Return
End If
Job.Release
Log("JOB RELEASE")
End Sub
[\code]

listview display all data ok, but just web the job is finished.

thanks

victor
 

DonManfred

Expert
Licensed User
Longtime User
I dont understand the question. Maybe try to explain in more clear english
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
ListView1.AddTwoLinesAndBitmap( trim_string(title),trim_string(title),LoadBitmapSample(File.DirAssets,"play2.png",15dip,15dip))
Why you are creating a new image each time if it is all the same...
Just use one.

B4X:
' Put this at the begin of Jobdone
dim bmp as Bitmap
bmp.initialize(File.DirAssets,"play2.png")

' then in your loop
ListView1.AddTwoLinesAndBitmap( trim_string(title),trim_string(title),bmp,15dip,15dip))
 
Upvote 0

victormedranop

Well-Known Member
Licensed User
Longtime User
My problem is that listview display data just when the job that download the data from the web is completed.
I just need to know if there is a way to start displaying the data in listview when the job is running to complete the job.

here is my code ("sorry me English not my default")

B4X:
Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
#SupportedOrientations: portrait
#CanInstallToExternalStorage: False
#IgnoreWarnings: 12
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
Dim job1 As HttpJob
Dim List1,List2,List3,List4,List5,List6 As List
End Sub
Sub Globals
Dim ListView1 As ListView
End Sub
Sub Activity_Create(FirstTime As Boolean)
ListView1.Initialize("Listview1")
List1.Initialize
List2.Initialize
List3.Initialize
List4.Initialize
List5.Initialize
List6.Initialize
job1.Initialize("Job1", Me)
ListView1.TwoLinesAndBitmap.Label.TextColor = Colors.ARGB(195,23,133,171)
Activity.AddView(ListView1, 0, 2%y, 100%x, 100%y)
Activity.LoadLayout("main")
job1.Download("http://ibsj.org/app/index.php")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub JobDone (Job As HttpJob)
Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
If Job.Success = True Then
Select Job.JobName
Case "Job1"
Log("JOB 1")
Dim parser As JSONParser
parser.Initialize(Job.GetString)
Dim root As List = parser.NextArray
For Each colroot As Map In root
Dim date As String = colroot.Get("date")
Dim thumb_url As String = colroot.Get("thumb_url")
Dim video_url As String = colroot.Get("video_url")
Dim author As String = colroot.Get("author")
Dim audio_url As String = colroot.Get("audio_url")
Dim title As String = colroot.Get("title")
List1.Add(date)
List2.add(trim_string2(thumb_url))
Log(trim_string2(thumb_url))
Log(thumb_url)
List3.Add(video_url)
List4.Add(RemoveAccents(author))
List5.Add(audio_url)
List6.Add(trim_string(title))
Log(trim_string(title))
display_data(title,author,thumb_url)
Next
End Select
Else
Log("Error: " & Job.ErrorMessage)
ToastMessageShow("Error: " & Job.ErrorMessage, True)
Return
End If
Job.Release
Log("JOB RELEASE")
End Sub
Sub display_data (data1 As String, data2 As String, data3 As String )
ListView1.Invalidate
ListView1.AddTwoLinesAndBitmap( trim_string(data1) , trim_string(data2),LoadBitmapSample(File.DirAssets,"play2.png",15dip,15dip))
End Sub
Sub RemoveAccents(s As String) As String
Dim normalizer As JavaObject
normalizer.InitializeStatic("java.text.Normalizer")
Dim n As String = normalizer.RunMethod("normalize", Array As Object(s, "NFD"))
Dim sb As StringBuilder
sb.Initialize
For i = 0 To n.Length - 1
If Regex.IsMatch("\p{InCombiningDiacriticalMarks}", n.CharAt(i)) = False Then
sb.Append(n.CharAt(i))
End If
Next
Return sb.ToString
End Sub
Sub trim_string (data As String) As String
If data.Length < 30 Then
Return data
Else
Dim result As String = data.SubString2(0,29 -1 )
Return result & " ..."
End If
End Sub
Sub trim_string2 (data As String) As String
Dim result As String
If data = "null" Or data.Length = 0 Or data = "" Or data = "vacio" Then
Else
result = data.SubString2(43,data.Length)
Return result
End If
Return ""
End Sub
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Adding DoEvents it works as you want.

Note that I changed also:
1) loaded the bitmap once
2) used a different image file because I haven't play2.png :D
3) added the ListVIew1 by Designer

Attached

P.S. Added also ListView1.SetSelection(ListView1.Size -1) to scroll the ListView
 

Attachments

  • Jobdone test.zip
    8.8 KB · Views: 178
Last edited:
Upvote 0
Top