Android 具有从指定文件夹拍摄的图像的listview

Android 具有从指定文件夹拍摄的图像的listview,android,image,listview,Android,Image,Listview,我有一个应用程序,其中listview是从db填充的 从这个数据库中,我获取一个文本和一个包含文件夹的字符串,如/sd card/my folder/image.jpg 我需要创建一个包含图像和文本的列表视图 我知道所有关于listview适配器和其他事情。。。但我不知道如何放置此图像,因为我没有id(例如getResources().getIdentifier(“foto_uu“+Integer.parseInt(data\u mio.getString(id\u immagine)),“dr

我有一个应用程序,其中listview是从db填充的

从这个数据库中,我获取一个文本和一个包含文件夹的字符串,如/sd card/my folder/image.jpg

我需要创建一个包含图像和文本的列表视图

我知道所有关于listview适配器和其他事情。。。但我不知道如何放置此图像,因为我没有id(例如
getResources().getIdentifier(“foto_uu“+Integer.parseInt(data\u mio.getString(id\u immagine)),“drawable”,getPackageName())

但只有绳子。。。。我能得到的最大值是一个可拉伸:-|

        String[] from = new String[] {"photo","description"};
        int[] to = new int[] {R.id.list_image,R.id.list_content};
        final SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,R.layout.lista, data_db, from, to); 
        list_inventario.setAdapter(adapter);
有任何帮助吗?

listView.setImageBitmap(BitmapFactory.decodeFile(Environment.getExternalStorageDirectory()+“/path\u to\u file”)

使用此选项

Bitmap bitmap = BitmapFactory.decodeFile("the path");

yourview.setImageBitmap(bitmap);

由于您知道文件的路径,因此可以使用标准Java I/O类非常轻松地打开它(假设它存储在SD卡上,对于内部存储,您需要使用不同的方法)

然后,可以创建一个可绘制图形,如下所示:

FileInputStream readFile = new FileInputStream("/sd-card/my-folder/image.jpg");
Drawable yourDrawable = Drawable.createFromStream(readFile, "image.jpg");
然后你可以像平常一样使用可拉丝

如果图像的路径是内部存储路径,则可以通过以下方式创建可绘制图像:

Drawable yourDrawable = Drawable.createFromStream(getAssets().open("/my-folder/image.jpg"), "image.jpg");

我自己找到了解决方案!非常简单

        String[] from = new String[] {"foto","descrizione"};
        int[] to = new int[] {R.id.prova,R.id.list_content};
        final SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,R.layout.lista, data_db, from, to); 
        list_inventario.setAdapter(adapter);
图像工作正常。
这就是满足感:-)

我编辑了第一篇文章。用我的简单适配器,我能做到吗?或者我必须使用另一个?我认为它很容易使用定制的适配器,扩展了BaseAdapter。很高兴知道你自己解决了这个问题。快乐编码