I get this Memory Error (bitmap size exceeds VM) when I scroll more than 5 elements of my Gallery. This is my last part of the app and I wish very badly to be finished. All my Gallery Images are 180x180. I have read some "memory error" topics on StackOverFlow but most of them tell me to convert my images into Bitmaps, which I don't know how it really works. If someone can post a solution code for my problem, I will be very grateful! Code here:
public ImageAdapter(Context c) {
mContext = c;
TypedArray a = obtainStyledAttributes(R.styleable.HelloGallery);
a.recycle();
}
public int getCount() {
return mImageIds.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(final int position, View convertView,ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater)
mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView=inflater.inflate(R.layout.l1,null);
}
HighscoreManager hm=new HighscoreManager();
hm.addScore(timePerWord);
ImageView imgView = (ImageView)convertView.findViewById(R.id.imageView1);
TextView txtView = (TextView)convertView.findViewById(R.id.textView2);
if(hm.getHighscoreString()[position]!=0)
txtView.setText("\t\t Avg.time: "+hm.getHighscoreString()[position]
);
txtView.setTextSize(20);
imgView.setImageResource(mImageIds[position]);
return convertView;
}
Where the .xml file L1 is: (not much of it, an image and a textview below)
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/l1"
android:layout_width="240dp"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="240dp"
android:layout_height="185dp"
android:layout_x="-1dp"
android:layout_y="-15dp"
android:src="@drawable/background" />
<TextView
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="38dp"
android:layout_x="0dp"
android:layout_y="169dp"
android:text=""
android:gravity="center" />
</AbsoluteLayout>