简体   繁体   English

如何将R.drawable资源添加到Android数组中?

[英]How to add R.drawable resources to an array for android?

我想在整数数组中调用R.drawable集的序列,以便以后可以通过选择访问它,但是我想动态地加载到R.drawable中,它对应于不同的名称。根据外部值输入没有进行硬编码。我尝试了很多,但是喜欢使用列表,集合,数组转换等。请在这方面为我提供一个片段或示例。谢谢。

I suppose, that best way to achieve this funcionality is by using ArrayAdapter of Integer . 我想,实现这种功能的最好方法是使用Integer的 ArrayAdapter

You will simply add drawble resources by id. 您只需按ID添加可绘制资源。

If you need to get resource id, but you will get string input from user, you can use this code: 如果您需要获取资源ID,但是将从用户那里获取字符串输入,则可以使用以下代码:

Android, getting resource ID from string? Android,从字符串获取资源ID?

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

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