我有三个字符串数组:
private String lv_arr[]={"News","Events","Other"};private String lv_arr_d[]={"Get the latest news","Latest events","Other description here"};private String lv_arr_icons[]={"news","events","other"};
我的列表在每个列表项中向右显示一个图标,右边是两行文字.
当我硬编码图像的名称(例如新闻)时,它可以正常工作.
ArrayList <HashMap <String,Object>> users = new ArrayList <HashMap <String,Object>> (); int l = lv_arr.length; for (int i = 0; i <l; i++) { HashMap <String,Object> user = new HashMap <String,Object> (); //get icons String uri = "drawable/"+lv_arr_icons[i]; user.put ( "icon",(Drawable)getResources().getDrawable( getResources().getIDentifIEr(uri,null,getPackagename())));//the above works ok if i set R.drawable.news user.put ( "label",lv_arr[i].toString()); user.put ( "description",lv_arr_d[i].toString()); users.add (user); } String[] names = {"icon","label","description"}; int[] vIEws = {R.ID.icon,R.ID.label,R.ID.description}; SimpleAdapter saimageItems = new SimpleAdapter(this.getApplicationContext(),users,R.layout.optionsListitem,names,vIEws); lv1.setAdapter(saimageItems); //lv1 is my ListVIEw
所有图像都在可绘制的文件夹中.
当我尝试传递他们的名字并从资源中获取资源时,任何想法为什么没有图像加载?
user.put ( "icon",getResources().getIDentifIEr(uri,"drawable",getPackagename()));总结
以上是内存溢出为你收集整理的android – drawable getResources().getIdentifier问题全部内容,希望文章能够帮你解决android – drawable getResources().getIdentifier问题所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)