0

So right now i am using this in my code. But now i am storing them in the assets folder and i need help on how to display a different image when you click the next or previous button. So basically i would have a certain amount of pictures in the assets folder and then two button a next and back to scroll through the images. How would i do this? Thanks

private int [] images = {R.drawable.airplane, R.drawable.bike, R.drawable.boat,
    R.drawable.bus2,R.drawable.car,R.drawable.train};
Dan
  • 63
  • 1
  • 2
  • 8

2 Answers2

0

Yes, you can save your strings in a resource file. For example:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- single string -->
    <string name="hello">Hello World</string>

    <!-- multiple strings as an array -->
    <string-array name="hello_array">
        <item>hello</item>
        <item>android</item>
        <item>world</item>
    </string-array>
</resources>

and later retrieve their references in your code as R.string.hello or R.array.hello_array respectively.

For more info, refer to this and this guide.

waqaslam
  • 67,549
  • 16
  • 165
  • 178
  • what if i have an array of strings? like 6 strings and i want to display them in the order that i put them? – Dan Oct 29 '13 at 09:22
  • Yes, then you need to use `string-array`. Please refer to [this](http://mobile.tutsplus.com/tutorials/android/android-string/) guide – waqaslam Oct 29 '13 at 09:23
0

You can have it like this, use HashMap.

HashMap<Integer, String> map = new HashMap<Integer, String>();
map.put(R.drawable.airplane, "Airplane");

then you can get the appropriate String by

String whatString = map.get(R.drawable.airplane);
Lawrence Gimenez
  • 2,662
  • 4
  • 34
  • 52