I am trying to display 6 images, which i have kept in res/drawable folder in the gridview.
but i get the following error
10-29 09:44:20.025: E/AndroidRun
Try reducing the size of your images according to the individual grid sizes. Check the link. How to resize Image in Android?
The images you are using are big.
Have a look at this article
OR
Scale your images down. - reduce their size and quality.
What is Happening here is that,,, the app is going out of heap size.So you have to decode the image in such a way that it will fall under the heap size.Do this code in your adapter
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater inflater = (LayoutInflater) mcontext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View gridView;
if(convertView == null){
gridView = new View(mcontext);
gridView = inflater.inflate(R.layout.imageview,null);
ImageView imageView =(ImageView)gridView.findViewById(R.id.imageView);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inDither = false;
options.inJustDecodeBounds = false;
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
options.inSampleSize = 3;
options.inPurgeable = true;
Bitmap icon = BitmapFactory.decodeResource(context.getResources(),
Imageid[position],options);
holder.imageView.setImageBitmap(icon);
}
else {
gridView = (View) convertView;
}
return gridView;
}