图像从 Sdcard 到 GridView?
在我的 Android 应用程序中,我想在 gridview 中显示来自网站的图像。我已经从 SD 卡下载了文件夹中的图像,现在我需要将此图像放入数组中以在 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);
}
}
In my android app I want to display in gridview images from a website. I have download the images in a folder from sdcard and now I need to put this images in an array for display on gridview. How can I do this? The code below is for only one image:
@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);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试查看此内容并循环浏览目录中的文件。
http://developer.android.com/reference/android /os/Environment.html#getExternalStorageDirectory%28%29
Try looking at this and looping through the files in the directory.
http://developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory%28%29