
我想向列表视图添加图像,我该怎么做?名称和类型显示正确.目前停留在这里.
.//other codes..try{ JsONArray arr = new JsONArray(res); for(int i=0;i<arr.length();i++){ HashMap<String, String> map = new HashMap<String, String>(); JsONObject e = arr.getJsONObject(i); map.put("placeID", ""+ e.getString("placeID")); map.put("placename",""+ e.getString("placename")); map.put("placeType", ""+ e.getString("placeType")); map.put("image", R.drawable.ball_green); myList.add(map); } }catch(JsONException e) { Log.e("log_tag", "Error parsing data "+e.toString()); } listadapter adapter = new SimpleAdapter(this, myList , R.layout.places, new String[] { "placename", "placeType" }, new int[] { R.ID.placename, R.ID.placeType });...//other codes我希望图像适当地像:
解决方法:
R.java类在构建时自动生成,并维护作为资源ID的整数的“列表”.换句话说,R.是一个整数,不直接表示资源(字符串,可绘制等).
由于您的HashMap期望键和值都使用String类型,因此您需要将ball_green资源ID转换为String.例…
map.put("image", String.valueOf(R.drawable.ball_green));为了再次使用它,当使用它来设置诸如ImageVIEw等小部件的图像时,必须将该String转换回Integer.
总结以上是内存溢出为你收集整理的Android:处理HashMap.put获取图像全部内容,希望文章能够帮你解决Android:处理HashMap.put获取图像所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)