Android Question Cards image

b4x-de

Active Member
Licensed User
Longtime User
Check this:


B4X:
Sub DownloadImage(Link As String, iv As ImageView)
   Dim j As HttpJob
   j.Initialize("", Me)
   j.Download(Link)
   Wait For (j) JobDone(j As HttpJob)
   If j.Success Then
     iv.Bitmap = j.GetBitmap
   End If
   j.Release
End Sub
 
Upvote 0

fishwolf

Well-Known Member
Licensed User
Longtime User

I cannot use this method, the content of cards are take from a other http request. I have this error if insert this code.

Error:
Calendar - 328: Resumable subs return type must be ResumableSub (or none).
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Upload a sample to check, or post your code.

It will be easier to help you
 
Upvote 0

fishwolf

Well-Known Member
Licensed User
Longtime User
My Card List:
Region  Project Attributes
    #ApplicationLabel: Card List
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
    #BridgeLogger: True
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private xui As XUI
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
   
    Private CLV1 As CustomListView
   
    Private ImagePoster As B4XView
    Private LabelDays As B4XView
    Private LabelGame As B4XView
    Private LabelStructure As B4XView
    Private LabelDistance As B4XView
   
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Main")
   
    CallJson
   
End Sub



Sub CallJson
    Dim GetJson As HttpJob
    Dim Url As String
    Url = "http:/xxxx.com/data.json"
   
    GetJson.Initialize("GetJson", Me)
    GetJson.Download2(Url, Array As String("param1", 1))
       
End Sub

Sub JobDone (Job As HttpJob)

    Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
    Log("JobTag = " & Job.Tag)
   
    If Job.Success == True Then
       
        Select Job.JobName
       
            Case "GetJson"
                Log(Job.GetString)
                ShowJson(Job.GetString)
        End Select
    End If
 
    Job.Release
 
End Sub

Sub ShowJson(JsonString As String) As Boolean
Dim JsonString As String
Dim Json As JSONParser
Dim GlobalMap As Map
Dim ResultMap As Map
Dim ValuesItems As List
Dim ValueMap As Map
Dim Row1 As String
Dim Row2 As String
Dim Row3 As String
Dim Row4 As String
Dim ImageFile As String
Dim ImageDownload As HttpJob
   
   
    Log (JsonString)
   
    Json.Initialize(JsonString)
   
    GlobalMap = Json.NextObject
    ResultMap = GlobalMap.Get("Result")
       
    Log("code=" & ResultMap.Get("code"))
    Log("details=" & ResultMap.Get("details"))
   
   
    ValuesItems = GlobalMap.Get("data")
   

   
    For i = 0 To ValuesItems.Size - 1
        ValueMap = ValuesItems.Get(i)
       
        Row1 = ValueMap.Get("row1")
        Row2 = ValueMap.Get("row2")
        Row3 = ValueMap.Get("row3")
        Row4 = ValueMap.Get("row4")
   
        ImageDownload.Initialize("", Me)
        ImageDownload.Download("http://image.jpg")

        Wait For (ImageDownload) JobDone(ImageDownload As HttpJob)
       
        ImageDownload.Release
           
        CLV1.Add(CreateCard(CLV1.AsView.Width, ImageFile, Row1, Row2, Row3, Row4), "")
       
    Next
   
    Return True
       
End Sub








Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Private Sub CreateCard(Width As Int, Image As String, Row1 As String, Row2 As String, Row3 As String, Row4 As String) As Panel
    Dim p As B4XView = xui.CreatePanel("")
   
    '    SetAlpha(p, 0.3)
   
    Dim height As Int = 105dip
    If GetDeviceLayoutValues.ApproximateScreenSize < 4.5 Then
        Log ("< 4.5")
        height = 310dip
    End If
    Log("Height=" & height)
   
   
    'height = 200dip
    p.SetLayoutAnimated(0, 0, 0, Width, height)
    p.LoadLayout("Card")
   
    LabelDays.Text = Row1
    LabelGame.Text = Row2
    LabelStructure.Text = Row3
    LabelDistance.Text = Row4

    ImagePoster.SetBitmap(xui.LoadBitmapResize(File.DirAssets, Image, ImagePoster.Width - 5dip, ImagePoster.Height-5dip, True))
    Return p
End Sub
 

Attachments

  • Main.zip
    104.3 KB · Views: 21
Upvote 0

josejad

Expert
Licensed User
Longtime User
You're using "Jobdone" sub, this must not be done. You must use WAIT FOR. See "tip 11" from Erel "Code Smells" post

See attached a small demo with B4XPages and SMM based on your attachment. (as you can see on the top of the ImageDownloader post it's better to use SMM)
Pay attention to the CLEARTEXT in the manifest to get the images with http and not with https.
I've changed your ImagePoster from B4XImageView to a panel.

You can add a gif to show the loading indicator in this panel while the images are being downloaded. See this post

 

Attachments

  • Cards.zip
    63.9 KB · Views: 36
Last edited:
Upvote 0

josejad

Expert
Licensed User
Longtime User
Sorry, how to the click on card?
Please, create a new thread for new questions.

Take a look to the xCustomListView tutorial. You can do whatever you want adding the _ItemClick event

B4X:
Private Sub CLV1_ItemClick (Index As Int, Value As Object)
    
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…