Android Question Loading and displaying images into ImageViewer at regular intervals

Sanxion

Active Member
Licensed User
Longtime User
Hi all

Does anybody have any code that loads a series of images into an image viewer and then displays them one at a time at a predefined interval - upon clicking on am image, a URL is loaded.

I suppose I want something similar to how Admob works.

Thanks
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Thanks for the response but my images are already in the app and don't require downloading.

Also, all the images are to be displayed in the same image view and not separate ones.
You need a timer and maybe a FileName variable you that changes in timer_Tick event and
B4X:
yourImageView.Bitmap=LoadBitmap(File.DirAssets,FileName)
 
Upvote 0

Sanxion

Active Member
Licensed User
Longtime User
You need a timer and maybe a FileName variable you that changes in timer_Tick event and
B4X:
yourImageView.Bitmap=LoadBitmap(File.DirAssets,FileName)

Could you give some sample code of how to loop through a list of images in the timer so it select the next one in the list?
Thanks.
 
Upvote 0

somed3v3loper

Well-Known Member
Licensed User
Longtime User
B4X:
Dim images as list
in Process_Globals

B4X:
images.Initialize

images.addall(array as string("file1","file2"))
probably in Activity_Create

and in timer_Tick event you might do this
B4X:
dim index as int =rnd(0,images.size-1)
yourImageView.Bitmap=LoadBitmap(File.DirAssets,images.get(index)

I am not sure whether it is the best way . someone might improve it
 
Upvote 0

somed3v3loper

Well-Known Member
Licensed User
Longtime User
That is if you want images to be chosen randomly
If not index should be a global variable and you increase its value each time you set a new image
B4X:
yourImageView.Bitmap=LoadBitmap(File.DirAssets,images.get(index)
if index>images.size-1 then
    index=0
else
    index = index+1
end if
 
Upvote 0

Sanxion

Active Member
Licensed User
Longtime User
That is if you want images to be chosen randomly
If not index should be a global variable and you increase its value each time you set a new image
B4X:
yourImageView.Bitmap=LoadBitmap(File.DirAssets,images.get(index)
if index>images.size-1 then
    index=0
else
    index = index+1
end if
Thank-you :)
 
Upvote 0
Top