listview中显示一个imageview
请教大虾一个问题,我现在是在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);
--------------------编程问答-------------------- 路径不对,你的图片在哪儿啊?SD卡上吗?那个“D:/images/a.png” 显然不对。
访问SD卡的文件这样写:/sdcard/myphoto/a.png 表示SD卡上的myphoto下的a.png文件。 --------------------编程问答--------------------
That's OK >_< --------------------编程问答--------------------
That's OK >_< --------------------编程问答-------------------- 路径应该是android里的sd卡路径,要自己在本地建个 --------------------编程问答-------------------- 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 }); --------------------编程问答-------------------- 学习了 --------------------编程问答-------------------- 做个记号 --------------------编程问答-------------------- --------------------编程问答-------------------- 5楼正解 --------------------编程问答-------------------- 那怎么得到本地数据库中图片的ID呢? --------------------编程问答--------------------
这个要用到数据库方面的库,原理是一样的!
补充:移动开发 , Android