2012-10-20 61 views
0

我有我的可绘制文件夹中的图像列表。 我有代码在coverflow中显示它们。 所以要引用图片,我可以使用以下方式使用R.drawable。 _等,见如下─如何引用ImageAdapter的SD卡图像

public class ImageAdapter extends BaseAdapter{ 

    private Context context; 
    private ImageView[] images; 
    private Integer[] imageids={ 
      R.drawable. image001, 
      R.drawable. image002, 
      R.drawable. image003, 
      R.drawable. image004, 
      R.drawable. image005, 
      R.drawable. image006, 

      R.drawable. image007, 
      R.drawable. image008, 
      R.drawable. image009, 

      R.drawable. image011, 

      R.drawable. image012, 
      R.drawable. image013, 
      R.drawable. image014, 
      R.drawable. image015, 
      R.drawable. image016, 

      R.drawable. image017, 
      R.drawable. image018, 
      R.drawable. image019, 
      R.drawable. image020, 
      R.drawable. image021, 
      R.drawable. image022, 
      R.drawable. image023, 
      R.drawable. image024, 

     }; 
    public ImageAdapter(Context con) 
    { 
     this.context=con; 
     images=new ImageView[imageids.length]; 
    } 
} 

现在的问题是如何引用上述图像标识列表我的SD卡的图像。 我在stackoverflow上找到一个相关的问题,但没有答案。 请任何人回答这个问题,如果知道。 我可以用同样的方式创建videoid的列表吗?

谢谢。

回答

2
/mnt/sdcard/pathtoyourfile 

可以用于指代sdcard中的文件。例如,如果你在SD卡有一个图像文件作为image.jpg文件的文件夹名为MyFolder中,你可以有,

Bitmap b = BitmapFactory.decodeFile("/mnt/sdcard/myfolder/image.jpg"); 
imageView.setImageBitmap(b); 

此路径可用于视频以及。正如我可以看到你的数组是Integer类型。而你可以使用一个String数组。

BitmapFactory.decodeFile(“”);用于将文件解码为位图。 Here你可以找到一个文档。

+0

嗨Ambrish, 谢谢。请告诉BitmapFactory.decodeFile在这里有什么用处? – Vishal

+0

看到我编辑的答案 – Vinay

+0

谢谢Ambrish。 它正在工作。 – Vishal