从Sdcard到GridView的图像?

时间:2011-07-26 14:03:23

标签: android image gridview sd-card android-sdcard

在我的Android应用程序中,我想在网站的gridview图像中显示。我已经从sdcard下载了一个文件夹中的图像,现在我需要将这些图像放在一个数组中以便在gridview上显示。我怎样才能做到这一点?以下代码仅适用于一张图片:

@Override
        public View getView(final int position, View convertView,
                ViewGroup parent) {
            View MyView = convertView;

            if (convertView == null) {
                /* we define the view that will display on the grid */

                // Inflate the layout
                // LayoutInflater li = getLayoutInflater();
                LayoutInflater li = (LayoutInflater) MyContext
                        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                MyView = li.inflate(R.layout.grid_item, null);

                // Add The Text!!!
                TextView tv = (TextView) MyView
                        .findViewById(R.id.grid_item_text);
                tv.setText("Item " + position);

                // Add The Image!!!
                ImageView iv = (ImageView) MyView
                        .findViewById(R.id.grid_item_image);

                Bitmap bitmap = BitmapFactory.decodeFile("sdcard/AndroidPlanet.png");
                iv.setImageBitmap(bitmap);

}
}

1 个答案:

答案 0 :(得分:0)