【发布时间】:2012-01-23 16:52:49
【问题描述】:
在我的应用程序中,我将 tableLayout 的内容保存为文件夹中的图像。为了允许用户从保存的图像中打开文件,我创建了一个包含这些文件名称的文本文件。这些文件名稍后将加载到一个数组(文件)中。用户单击“打开”以查看文件名列表并选择他要打开的文件名。我正在使用以下代码打开文件。
final String imageInSD = extStorageDirectory+"/myFolder/"+files[which];
//where 'files' is an array of strings and contains the names of files.
//and 'which' is the index of the selected element in the list
Bitmap bitmap = BitmapFactory.decodeFile(imageInSD);
ImageView ivv=(ImageView) findViewById(R.id.imageView);
ivv.setImageBitmap(bitmap);
当我尝试它时没有任何反应,所以我尝试了以下
final String imageInSD = extStorageDirectory+"/myFolder/myFile.PNG";
Bitmap bitmap = BitmapFactory.decodeFile(imageInSD);
ImageView ivv=(ImageView) findViewById(R.id.imageView);
ivv.setImageBitmap(bitmap);
它会显示名为 myFile 的图像。 我已经检查过我是否获得了正确的文件名和路径,并且它似乎是正确的。 (当我单击列表中的 myFile.PNG 并显示我得到“/mnt/sdcard/myFolder/myFile.PNG”的路径时)。
为什么我使用第一个代码时它不起作用?
【问题讨论】: