我一直在創建圖像的網格視圖,圖像出現在Assets文件夾中。 Opening a File from assets folder in android鏈接幫助我使用位圖來讀取它。我目前遇到的代碼是:Android - 來自GridView中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
是否有一個特定的原因,你把這些在資產/'而不是作爲drawable資源? – CommonsWare 2010-05-02 13:09:18
其實我想要動態加載這些圖片,而且它們的數量很多。當我擁有資源時,我有記憶問題.ContentProvider有點失控,所以我想我會試用資產。 - Saran – Saran 2010-05-02 16:29:04