Reputation: 3
I have created a folder called Items
in /mnt/sdcard/
, from where I want to find JPG
images. Then I want to display a ListView
with all the names of the listed images. Upon clicking on one of the names in the list, I would like the image from the path display in an ImageView
. I have troubles finding the images.
How can I do this?
Upvotes: 0
Views: 4619
Reputation: 24460
The External Storage path differs from device to device and I strongly suggest you are not using /mnt/sdcard/
but rater Environment.ExternalStorageDirectory
.
You should be able to use normal C# file operations to get a list of files.
string[] filePaths = Directory.GetFiles(Environment.ExternalStorageDirectory, "*.jpg");
You can use the filePaths to pass to your custom Adapter
and inside that load the Bitmap
s if you want to display them inside of the ListView
:
using(var bitmap = BitmapFactory.DecodeFile(filePaths[position]))
imageView.SetImageBitmap(bitmap);
or you can simply use a SimpleAdapter
and pass it the filePaths
, which will then display them as strings.
Then you just need to hook up the ItemClick
event to get the position in the list clicked and load the correct Bitmap
into an ImageView.
Also please read http://docs.xamarin.com/recipes/android/resources/general/load_large_bitmaps_efficiently if you are using large images, as you have very limited resources.
A good resource for Custom List Adapters: http://redth.info/2010/10/12/monodroid-custom-listadapter-for-your-listview/
Upvotes: 1