请教大虾一个问题,我现在是在listview中显示一个imageview,imageview的src来自数据库的地址,但是不知道怎么显示图片,ID 和Name都可以正常显示
我试着把代码_rs.getString("AppType_ICON")直接改成 “D:/images/a.png” 这样也不行
我用File f = new File(“_rs.getString("AppType_ICON")”); 发现f=null;但是路径是正确的。以下是代码
ResultSet _rs = null;
_rs = _sqlhelp.ExecuteSql(_Sql); ArrayList<HashMap<String, Object>> _arrAppType = new ArrayList<HashMap<String, Object>>();
HashMap<String, Object> _MapEntityAppType = null;
try {
while (_rs.next()) { _MapEntityAppType = new HashMap<String, Object>(); _MapEntityAppType.put("ID", _rs.getString("AppType_ID"));
_MapEntityAppType.put("Img", _rs.getString("AppType_ICON"));
_MapEntityAppType.put("Name", _rs.getString("AppType_Name"));
_arrAppType.add(_MapEntityAppType);
System.out.println(fileName);
}
listViewAPP2 = (ListView) findViewById(R.id.listViewAPP2);
SimpleAdapter sAdapter = new SimpleAdapter(this, _arrAppType,
R.layout.apptyleitem, new String[] { "ID", "Name", "Img" },
new int[] { R.id.textViewAppTypeID,
R.id.textViewAppTypeName, R.id.imgAppType }); listViewAPP2.setAdapter(sAdapter);

解决方案 »

  1.   

    路径不对,你的图片在哪儿啊?SD卡上吗?那个“D:/images/a.png” 显然不对。
    访问SD卡的文件这样写:/sdcard/myphoto/a.png 表示SD卡上的myphoto下的a.png文件。
      

  2.   

    路径应该是android里的sd卡路径,要自己在本地建个
      

  3.   

    SimpleAdapter中对应的第二个参数应该是资源的id数组 Map<String, Object> map = new HashMap<String, Object>();
    map.put("PIC", R.drawable.pic);//这里是图片的id,是整型的,对应R.java中的id,build时自动生成的。
    map.put("TITLE", "Test Title");
    map.put("CONTENT", "Test Content");
    contents.add(map); SimpleAdapter adapter = new SimpleAdapter(this,
    (List<Map<String, Object>>) contents, R.layout.listitem,
    new String[] { "PIC", "TITLE", "CONTENT" }, new int[] {
    R.id.listitem_pic, R.id.listitem_title,
    R.id.listitem_content });