0

Hi I am new in programming..

I want to show a random GIF image to ImageView using Ion. For single GIF it is ok, I simply use this line

 Ion.with(imgView3).load("file:///android_asset/gif130407.gif"); 

But I have multi GIF images in multi directories in assets folder and I want first check the directory and gets all GIFs as array passing to Random and then show the Random id to ImageView using Ion I try it with png and Drawables its work perfect, but Ion "load" method gets a string address of the file how can I do this.

behking
  • 9
  • 4

1 Answers1

0

If you know specificly, where your gifs are, you could create a String Array or ArrayList with item type String. Then you can take it and get a random gif by putting in a Random index.

Otherwise if you want it, you are doing now, with the resource ids, you can look for the getResource methods in your context/activity. But i would prefer a list. If you could write a bit more detailed, why you need these random gifs (e.G. Security-Check, Game, EasterEgg...), i can give you a better answer.

Luftbaum
  • 303
  • 1
  • 13
  • It's just a simple memory app and is my first app and I am trying to learn android with making it. I loop in assets and have file names as"ArrayList items" know I want to get this items and convert to an int [] to pass it to Random and get random index and then use this index in Ion syntax for images it is as simple as this int rand = new Random().nextInt(images.length); imgView2.setImageResource(images[rand]); But load" " make me confuse – behking Mar 20 '16 at 10:23
  • I dont really understand the tricky part, but if I do: take your assests folder (where your gifs are) with the normal java.io File and take the array / list of the files in it. Here you could simply take a random index and you will get a random gif file randomFileName. Now you can take your Ion.load and modify the path Input with the result (String path = "file:///android_asset/" + randomFileName ). I hope, this helps you with your problem. – Luftbaum Mar 20 '16 at 11:06