【发布时间】:2012-12-07 12:25:03
【问题描述】:
我正在从手机上的选定文件夹中读取文件,如下面的代码所示。 我怎么能用 Imagefile 来完成这项工作? 最后,我喜欢有一个图像列表,其中包含每个图像的预览。 像这样:
[IMG] (imgview) - [文件名] (字符串)
for(int i=0; i < files.length; i++) {
File file = files[i];
map = new HashMap<String, String>();
if(!file.isHidden() && file.canRead()) {
path.add(file.getPath());
if(file.isDirectory()) {
map.put("img_list", ""+R.drawable.folder);
map.put("string_cell", file.getName()+"/");
your_array_list.add(map);
}else{
ImageFileFilter filefilter = new ImageFileFilter(file);
if(filefilter.accept(file)){
//Its an imagefile
// ==> I like to replace the ""+R.drawable.image with the file that I have read
map.put("img_list", ""+R.drawable.image);
} else {
//Its not an image file
}
map.put("string_cell", file.getName());
your_array_list.add(map);
}
}
}
SimpleAdapter mSchedule = new SimpleAdapter(this, your_array_list, R.layout.connected_upload_row,
new String[] {"img_list", "string_cell"}, new int[] {R.id.img_list, R.id.string_cell});
list.setAdapter(mSchedule);
在下面的图片中,我喜欢将白色的“图像”图片替换为名为“41786486733.jpg”的原始图片作为预览。 这样用户就可以看到这是什么图片了……
编辑弗洛里安皮尔兹
if(filefilter.accept(file)){
Log.v("PATH1", file.getPath() );
ImageView myImageView = (ImageView) findViewById(R.id.img_list);
Bitmap bmp = BitmapFactory.decodeFile(file.getAbsolutePath());
myImageView.setImageBitmap(bmp);
}
【问题讨论】:
-
你需要实现一个自定义的列表视图,这里看一个例子[链接][1][1]:stackoverflow.com/questions/10267103/…
-
为什么你要创建两次HashMap实例
map = new HashMap<String, String>();删除最后一个 -
谜题我正在使用自定义列表视图 ;) ρяσѕρєя 每次你必须重新初始化 HashMap 否则它不起作用......
-
@MarcoSeiz : 把
map = new HashMap<String, String>();放在`File file = files[i];`里面for循环和remove`map = new HashMap();`从每个地方和plz清楚地告诉我你正在解决的当前问题是什么 -
@ρяσѕρєя 我在我的问题中添加了一张图片来解释我想要什么。谢谢和欢呼:)
标签: android image listview hashmap simplecursoradapter