我一直在创建一张图片的网格视图,这些图片都存储在Assets文件夹中。 打开Android中Assets文件夹中的文件 这篇文章帮助我使用位图来读取它。我目前拥有的代码是:
public View getView(final int position, View convertView, ViewGroup parent)
{
try
{
AssetManager am = mContext.getAssets();
String list[] = am.list("");
int count_files = imagelist.length;
for(int i= 0;i<=count_files; i++)
{
BufferedInputStream buf = new BufferedInputStream(am.open(list[i]));
Bitmap bitmap = BitmapFactory.decodeStream(buf);
imageView.setImageBitmap(bitmap);
buf.close();
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
我的应用程序可以从Assets文件夹读取图像,但它没有遍历网格视图中的单元格。网格视图的所有单元格都使用从图像集中选择的相同图像。有人能告诉我如何遍历单元格并仍然具有不同的图像吗?
我在一个ImageAdapter类中拥有上述代码,该类扩展了BaseAdapter类,在我的主类中,我通过以下方式将其与我的gridview链接:
GridView gv =(GridView)findViewById(R.id.gridview);
gv.setAdapter(new ImageAdapter(this, assetlist));
提前感谢您的帮助,Saran