简体   繁体   English

单击按钮访问资产文件夹中的图像

[英]access images from assets folder with a button click

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. 因此,基本上我将在assets文件夹中拥有一定数量的图片,然后再单击两个按钮,然后向后滚动以浏览图像。 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};

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. 然后在您的代码中分别以R.string.helloR.array.hello_array检索它们的引用。

For more info, refer to this and this guide. 欲了解更多信息,请参阅指南。

You can have it like this, use HashMap . 您可以使用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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM