私がスクロールしたときに私の問題とOutOfMemory
エラーが発生ListView
とGridView
の両方を持っているが、私はので、私はスニル初のソリューションを使用し、私のコードでそれを実装する問題についてオンラインで読むとthis質問を見ました。 GridView
ためとListView
画像は「/res/drawable/image1.png」であるというように、私はCustomAdapter
クラスにこのint配列public static int[] mDrawableImg = {R.drawable.back, R.drawable.arrows, R.drawable.bomber, R.drawable.archers, R.drawable.knight};
に合格し、この使用:今、あなたは、私が追加参照としてアンドロイドリストビューのOutOfMemory - ImageBitmaps
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
final Holder holder = new Holder();
final View rowView = inflater.inflate(R.layout.program_list2, null);
holder.img = (ImageView) rowView.findViewById(R.id.imageView1);
holder.img.setImageResource(imageId[position]);
// holder.img.setImageBitmap(convertBitmap(String.valueOf(imageId[position])));
return rowView;
}
をconvertBitmap
という機能を持つBitmap
から画像をロードするコード行は、私のGridView
は空です。そのスクロール可能な意味は項目がありますが、画像はロードされません。
convertBitmap
機能:
public static Bitmap convertBitmap(String path) {
Bitmap bitmap = null;
BitmapFactory.Options bfOptions = new BitmapFactory.Options();
bfOptions.inDither = false;
bfOptions.inTempStorage = new byte[32 * 1024];
File file = new File(path);
FileInputStream fs = null;
try {
fs = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
if (fs != null) {
bitmap = BitmapFactory.decodeFileDescriptor(fs.getFD(), null, bfOptions);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fs != null) {
try {
fs.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return bitmap;
}
は私が間違って何をした、それは私のOutOfMemory
エラーを解決するのだろうか?ありがとう。
あなたはrowViewを返していますが、存在しません。どうすればいいですか? – DAVIDBALAS1
@ DAVIDBALAS1Oh、私の間違い。編集された答えを見てください。あなたは同じconvertViewを使用する必要があります –
とにかく残念なことにスクロールはまだ少し遅いです。 – DAVIDBALAS1