Android的getResources /则getIdentifier不返回ID [英] Android getResources/getIdentifier not returning ID

查看:228
本文介绍了Android的getResources /则getIdentifier不返回ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有code像tthis:

I have code like tthis:

String s = "replace__menu__" + data.imageid + ".png";
int RID = this.getApplicationContext().getResources().getIdentifier(s, "drawable-hdpi", getPackageName());

的String = 的指令设置一个值,该值是一样的名字在我的RES /绘制,华电国际文件之一。但是,返回的值集的 RID 应用于值的 0

The String s = instruction sets a value that is the same as one of names in my res/drawable-hdpi folder. However, the returned value sets RID to the value 0

任何想法,为什么我的code不工作?难道我做错了什么?

Any idea why my code is not working? Am I doing something wrong?

推荐答案

试试这个

String s = "replace__menu__" + data.imageid;  // image name is needed without extention
int RID = this.getApplicationContext().getResources().getIdentifier(s, "drawable", getPackageName());

这篇关于Android的getResources /则getIdentifier不返回ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆