Android Question Logic Question For Each

Douglas Farias

Expert
Licensed User
Longtime User
Hi all
i m trying to understand and find a ideia but not sucess
i go try show a sample

i m get a json result like this

B4X:
{"Success":true,"Sent":{"Has":false},"NotSent":{"Has":false,"Amount":4,"Thumbnails":[{"PhotoID":"43","Url":"http:\/\/www.lala.com\/lala\/\/Files\/Users\/18\/Thumbnails\/0378750001408127092f58cd017a3b80ef6d315192973ebf7a2.jpg"},{"PhotoID":"42","Url":"http:\/\/www.lala.com\/lala\/\/Files\/Users\/18\/Thumbnails\/0378750001408126725123518fd3f73a70c4c1c65de84c4981a.jpg"},{"PhotoID":"41","Url":"http:\/\/www.lala.com\/lala\/\/Files\/Users\/18\/Thumbnails\/0191250001408126603f58cd017a3b80ef6d315192973ebf7a2.jpg"},{"PhotoID":"40","Url":"http:\/\/www.lala.com\/lala\/\/Files\/Users\/18\/Thumbnails\/0035000001408125442123518fd3f73a70c4c1c65de84c4981a.jpg"}]}}


Ok the result is 4 images,
Amount = 4

i have 10 imagesview (img1, img2, img3, img4 etc...)

i mm trying to get the result with for each

B4X:
                        Dim Thumbnails As List = NotSent.Get("Thumbnails") 
                        For Each colThumbnails As Map In Thumbnails
                        Dim Url As String = colThumbnails.Get("Url")
                        Log(Url)
                        Dim photoid As String = colThumbnails.Get("PhotoID")
                        Log(photoid)
                        Next

The result is

Ok now my question

how can I separate/divede this result?
getlink1 only and load this on imageview1

getlink2 load this on imageview2

getlink3 load this on imageview3 etc...

i never know the result amount of links, can is 2 photos or 3 max 10 (1 - 10)

thx to all, i m trying to learn *-*
 
Last edited:

udg

Expert
Licensed User
Longtime User
Hi Douglas,

have a look at this Erel's tutorial here.
A List instead of an array could solve the unknown number of pictures returned problem.

Umberto
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
B4X:
Dim Thumbnails As List = NotSent.Get("Thumbnails")
Log(Thumbnails.Size)

Thumbnails is a LIST in this case. Learn how to use lists and you should be able to access any of the results.
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
Dim Thumbnails AsList = NotSent.Get("Thumbnails")Log(Thumbnails.Size)
Thumbnails is a LIST in this case. Learn how to use lists and you should be able to access any of the results.

Ok i have try make this but this show 4 4 4 4

i try to use
Thumbnails.Get(0)
and this show the 4 links, i dont know why =(



Here with Log(Thumbnails.Size)
** Activity (telaprincipal) Pause, UserClosed = false **
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
** Activity (telaprincipal) Resume **
{"Success":true,"Image":"http:\/\/74.63.193.55\/clickfight\/derp\/\/Files\/Users\/18\/Resamplings\/011312500140818138865f3495c78f055c17ea5ae448568cf16.jpg","Thumbnail":"http:\/\/74.63.193.55\/clickfight\/derp\/\/Files\/Users\/18\/Thumbnails\/011312500140818138865f3495c78f055c17ea5ae448568cf16.jpg"}
{"Success":true,"Sent":{"Has":false},"NotSent":{"Has":true,"Amount":4,"Thumbnails":[{"PhotoID":"92","Url":"http:\/\/74.63.193.55\/clickfight\/derp\/\/Files\/Users\/18\/Thumbnails\/011312500140818138865f3495c78f055c17ea5ae448568cf16.jpg"},{"PhotoID":"91","Url":"http:\/\/74.63.193.55\/clickfight\/derp\/\/Files\/Users\/18\/Thumbnails\/048812500140818135265f3495c78f055c17ea5ae448568cf16.jpg"},{"PhotoID":"90","Url":"http:\/\/74.63.193.55\/clickfight\/derp\/\/Files\/Users\/18\/Thumbnails\/084750000140818123265f3495c78f055c17ea5ae448568cf16.jpg"},{"PhotoID":"89","Url":"http:\/\/74.63.193.55\/clickfight\/derp\/\/Files\/Users\/18\/Thumbnails\/02850000014081471209c99c6a3874a5cba1a390b38387e9235.jpg"}]}}
4
4
4
4



here with Thumbnails.Get(0)

** Activity (main) Resume **
Installing file.
** Activity (main) Pause, UserClosed = false **
PackageAdded: package:click.fight.vallow
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (httputils2service) Create **
** Service (httputils2service) Start **
** Activity (main) Pause, UserClosed = false **
** Activity (telaprincipal) Create, isFirst = true **
** Activity (telaprincipal) Resume **
** Activity (telaprincipal) Pause, UserClosed = false **
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
** Activity (telaprincipal) Resume **
{"Success":true,"Image":"http:\/\/74.63.193.55\/clickfight\/derp\/\/Files\/Users\/18\/Resamplings\/053500000140818158465f3495c78f055c17ea5ae448568cf16.jpg","Thumbnail":"http:\/\/74.63.193.55\/clickfight\/derp\/\/Files\/Users\/18\/Thumbnails\/053500000140818158465f3495c78f055c17ea5ae448568cf16.jpg"}
{"Success":true,"Sent":{"Has":false},"NotSent":{"Has":true,"Amount":4,"Thumbnails":[{"PhotoID":"93","Url":"http:\/\/74.63.193.55\/clickfight\/derp\/\/Files\/Users\/18\/Thumbnails\/053500000140818158465f3495c78f055c17ea5ae448568cf16.jpg"},{"PhotoID":"92","Url":"http:\/\/74.63.193.55\/clickfight\/derp\/\/Files\/Users\/18\/Thumbnails\/011312500140818138865f3495c78f055c17ea5ae448568cf16.jpg"},{"PhotoID":"91","Url":"http:\/\/74.63.193.55\/clickfight\/derp\/\/Files\/Users\/18\/Thumbnails\/048812500140818135265f3495c78f055c17ea5ae448568cf16.jpg"},{"PhotoID":"90","Url":"http:\/\/74.63.193.55\/clickfight\/derp\/\/Files\/Users\/18\/Thumbnails\/084750000140818123265f3495c78f055c17ea5ae448568cf16.jpg"}]}}
{Url=http://74.63.193.55/clickfight/derp...40818158465f3495c78f055c17ea5ae448568cf16.jpg, PhotoID=93}
{Url=http://74.63.193.55/clickfight/derp...40818158465f3495c78f055c17ea5ae448568cf16.jpg, PhotoID=93}
{Url=http://74.63.193.55/clickfight/derp...40818158465f3495c78f055c17ea5ae448568cf16.jpg, PhotoID=93}
{Url=http://74.63.193.55/clickfight/derp...40818158465f3495c78f055c17ea5ae448568cf16.jpg, PhotoID=93}
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Hi Douglas,

as far I can see, you print 4 times the same log: Thumbnails.Size -->(4 4 4 4) or Thumbnails.Get(0) --> (PhotoID93).
You should loop from min to max (0 to Size-1) to have your four distinct values.

Umberto
 
Upvote 0

udg

Expert
Licensed User
Longtime User
I don't know how you set up the ImageView init code, but following Erel's code linked on post #2, you could do something like the following (it's more a concept scheme than a real code example):

B4X:
Sub Globals
Dim ImageView1 As ImageView
Dim ImageView2 As ImageView
Dim ImageView3 As ImageView
...
Dim ImageView9 As ImageView
Dim ivs() As ImageView
End Sub

Sub Activity_Create(FirstTime AsBoolean)
Activity.LoadLayout("1")
ivs = Array As ImageView(ImageView1, ImageView2, ImageView3, ImageView4, _
ImageView5, ImageView6, ImageView7, ImageView8, ImageView9)
End Sub

' when you got your JSON result do something like:

Dim Thumbnails As List = NotSent.Get("Thumbnails")
Dim maxel,j as int
maxel = Thumbnails.Size
if maxel > 9 then maxel = 9 'discard eventual extra URLs
for j = 0 to maxel-1 do
   dim colThumbnails As Map
   colThumbnails = Thumbnails.Get(j)
    Dim Url AsString = colThumbnails.Get("Url")
    Log(Url)
    Dim photoid AsString = colThumbnails.Get("PhotoID")
    Log(photoid)
    assigntheimage(j,url,photoid)
next

sub assigntheimage(index as int, url as string, id as int)
' download the image
' ivs(index).tag = ID
'ivs(index).background = image
end sub

Consider the option of generating at runtime the imageviews you deserve.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Hi Douglas,

have a look at NJDUde's Grid library. It will easy your work a lot.
 
Upvote 0

Similar Threads

Top