Displaying pictures in a gridview - android

I am trying to display pictures that I had placed in the drawable folder using a Gridview. I am getting some errors. My code and the errors I am getting are shown below.
package com.newapp;
import android.R;
import android.R.drawable;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;/*Error here: main cannot be resolved or is not a field*/
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);/*Error here: main cannot be resolved or is not a field*/
GridView gridview = (GridView) findViewById(R.id.photogrid);
gridview.setAdapter(new ImageAdapter(this));
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Toast.makeText(MainActivity.this, "" + position, Toast.LENGTH_SHORT).show();
}
});
}
}
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) { // if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
// references to our images
private Integer[] mThumbIds = {
R.drawable.sample_0, /*Error here: sample_0 cannot be resolved and is not a field*/
R.drawable.sample_1,/*Error here: sample_1 cannot be resolved and is not a field*/
R.drawable.sample_2,/*Error here: sample_2 cannot be resolved and is not a field*/
R.drawable.sample_3,/*Error here: sample_3 cannot be resolved and is not a field*/
R.drawable.sample_4,/*Error here: sample_4 cannot be resolved and is not a field*/
R.drawable.sample_5/*Error here: sample_5 cannot be resolved and is not a field*/,
R.drawable.sample_6,
/*Error here: sample_6 cannot be resolved and is not a field*/
};
}
So can somebody tell me what is causing these problems? Any help will be much appreciated.
Thanks in advance

Here is your first problem: import android.R
Do not import this as this is the android system's R package, and not your own project's R file, hence main cannot be identified, as the R you are referring to for main in the android.R package does not exist.
If you remove this import, "main" will be recognized, as your own R file will be referenced. The same rule applies for the ImageAdapter. If your remove the import: import android.R.drawable you will avoid the problems you have in this class.

Related

The activity is blank something wrong with the custom gird Adapter code?

I'm testing a simple grid adapter with a custom object, the app runs on the device without a problem but stays blank instead of inflating the activity with the specified grid items. This is my code.
Main Activity
package com.example.nobodyme.errorrepository;
import android.app.Activity;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.Toast;
import android.view.View;
import android.widget.AdapterView.OnItemClickListener;
import java.util.ArrayList;
public class MainActivity extends ActionBarActivity {
GridView gridView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayList<GridItems> gridItems = new ArrayList<>();
gridItems.add(new GridItems("Android", 2));
gridItems.add(new GridItems("Java", 3));
gridView = (GridView) findViewById(R.id.gridView1);
gridView.setAdapter(new GridViewAdapter(this, gridItems));
}
}
GridViewAdapter
package com.example.nobodyme.errorrepository;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.List;
public class GridViewAdapter extends ArrayAdapter<GridItems> {
private Context context;
int b;
public GridViewAdapter(Context context, List<GridItems> gridItems) {
super(context, 0, gridItems);
b=gridItems.size();
}
public View getView(int position, View convertView, ViewGroup parent) {
View gridView = convertView;
if(gridView == null)
{
gridView = LayoutInflater.from(getContext()).inflate(
R.layout.grid_view, parent, false);
}
GridItems currentgriditem = getItem(position);
TextView mMaintextView = (TextView) gridView.findViewById(R.id.grid_item_main);
mMaintextView.setText(currentgriditem.getTitle());
TextView mUnansweredtextView = (TextView) gridView.findViewById(R.id.grid_item_unanswered);
mUnansweredtextView.setText(currentgriditem.getUnansweredNo());
return gridView;
}
#Override
public int getCount() {
return b;
}
#Override
public long getItemId(int position) {
return 0;
}
}
GridItems
package com.example.nobodyme.errorrepository;
/**
* Created by nobodyme on 15/1/17.
*/
public class GridItems {
/** Grid title*/
private String mTitle;
/** NO of unanswered items in the gird **/
private Integer mUnansweredNo;
public GridItems(String Title, Integer UnansweredNo) {
mTitle = Title;
mUnansweredNo = UnansweredNo;
}
public String getTitle() {
return mTitle;
}
public Integer getUnansweredNo() {
return mUnansweredNo;
}
}
I have edited the code as per the comments and the app still crashes.
You're overriding getCount and returning zero in the adapter. Don't override this, or return the correct number of items.
Please check below code :
#Override
public int getCount() {
return gridItems.size();
}
Instead of 0 returning, You should return your list size.
You need define gridItems List on your arrayAdapter and set it on the constructor
and override getCount to return the gridItems (adapterGridItems) size
private List<GridItems> adapterGridItems;
public GridViewAdapter(Context context, List<GridItems> gridItems) {
super(context, 0, gridItems);
//set adapterGridItems
this.adapterGridItems=gridItems;
}
#Override
public int getCount() {
return adapterGridItems.size();
}
please, check
mMaintextView.setText(currentgriditem.getUnansweredNo());
you are passing a integer so mMainTextView.setText will find a resource with currentgriditem.getUnansweredNo() id, i think you are trying to set currentgriditem.getUnansweredNo() as string, so this will work
mMaintextView.setText(currentgriditem.getUnansweredNo()+"");
are you sure that is mMaintextView.setText(currentgriditem.getUnansweredNo()+"");
and not
mUnansweredtextView.setText(currentgriditem.getUnansweredNo()+"");
?
In order to tell the adapter how many GridItems to show we need to override the getCount method as shown above by #samsad.
The reason the compiler complains that it can't recognize symbol griditems is because you haven't created a field to store a reference to the GridItems in your adapter.
Try creating a field for the ArrayList of GridItems in your adapter to fix the issue.

Android Grid View Images : Show Text

I have prepared a grid view in a fragment which shows images and when you click on them it shows the image in another Activity. I want the name of the image to be shown below it for that i took a textview but it shows position. How to show the name of the photo choosen from grid view on that textview. Below is the code fragments.
full_image_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView android:id="#+id/full_image_view"
android:layout_width="500dp"
android:layout_height="500dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="#+id/image_title"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
FullImageFragment
package com.androidbelieve.HIT_APP;
import android.app.Activity;
/**
* Created by Akash on 2/13/2016.
*/
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;
public class FullImageFragment extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.full_image_layout);
// get intent data
Intent i = getIntent();
// Selected image id
int position = i.getExtras().getInt("id");
ImageAdapter imageAdapter = new ImageAdapter(this);
ImageView imageView = (ImageView) findViewById(R.id.full_image_view);
imageView.setImageResource(imageAdapter.mThumbIds[position]);
TextView textView = (TextView) findViewById(R.id.image_title);
textView.setText(String.valueOf(position));
}
}
GalleryFragment
package com.androidbelieve.HIT_APP;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
/**
* Created by Ratan on 7/29/2015.
*/
public class GalleryFragment extends Fragment {
private GridView gridView;
private ImageView imageView;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View view = inflater.inflate(R.layout.fragment_gallery_grid, container,
false);
GridView gridView = (GridView) view.findViewById(R.id.grid_view);
gridView.setAdapter(new ImageAdapter(view.getContext()));
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent i = new Intent(getActivity(),FullImageFragment.class);
i.putExtra("id",position);
startActivity(i);
}
});
return view;
}
}
Please Help Me Out!!!
ImageAdapter
package com.androidbelieve.HIT_APP;
/**
* Created by Akash on 2/13/2016.
*/
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import java.util.ArrayList;
public class ImageAdapter extends BaseAdapter {
private Context mContext;
// Keep all Images in array
public Integer[] mThumbIds = {
R.drawable.akash, R.drawable.akash,
R.drawable.akash , R.drawable.akash,
};
// Constructor
public ImageAdapter(Context c){
mContext = c;
}
#Override
public int getCount() {
return mThumbIds.length;
}
#Override
public Object getItem(int position) {
return mThumbIds[position];
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = new ImageView(mContext);
imageView.setImageResource(mThumbIds[position]);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setLayoutParams(new GridView.LayoutParams(200, 200));
return imageView;
}
}
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent i = new Intent(getActivity(),FullImageFragment.class);
i.putExtra("id",position);
i.putExtra("image_name",arrayImageName[position]); // get your selected image name and pass it
startActivity(i);
}
});
In your image display class,
String name = i.getExtras().getString("image_name");
TextView textView = (TextView) findViewById(R.id.image_title);
textView.setText(name);
You can do this way:
// Keep all Images in array
public Integer[] mThumbIds = {
R.drawable.akash, R.drawable.akash,
R.drawable.akash , R.drawable.akash,
};
public String[] mThumbNames = {
"akash 0", "akash 1","akash 2", "akash 3",
};
In Next Activity:
TextView textView = (TextView) findViewById(R.id.image_title);
textView.setText(imageAdapter.mThumbNames[position])
Edit 1:
private class CustomClass{
public int drawable;
public String title;
public String information;
}
ArrayList<CustomClass> listCustom = new ArrayList<>();
Integer[] mThumbIds = {
R.drawable.akash, R.drawable.akash,
R.drawable.akash , R.drawable.akash,
};
String[] mThumbNames = {
"akash 0", "akash 1","akash 2", "akash 3",
};
String[] mThumbInfos = {
"akash 0 Info", "akash 1 Info","akash 2 Info", "akash 3 Info",
};
for (int i = 0; i < mThumbIds.length; i++) {
CustomClass customClass = new CustomClass();
customClass.drawable = mThumbIds[i];
customClass.title = mThumbNames[i];
customClass.information = mThumbInfos[i];
listCustom.add(customClass);
}
Hope this will help you.
I think you want something like this?
Hiren Patel has already answered that. I am just putting it in steps.
1) create 'CustomClass' which will act as POJO class to structure your image name, resource reference.
2) Create an adapter with extends ArrayAdapter and take 'CustomClass' as argument
3) In your activity, create a list of that class and load the data (Image name, resource id etc)
4)Initialize your adapter with above list (can be array as well)
5) access that values on getView method of adapter

How to reset the whole View by clicking the delete Button

I have made a custom View which contains an ImageView, a TextView and a delete Button.
I want to reset the particular View when I click the delete Button associated with it.
Please tell how to implement this.
Here is my MainActivity.java
package com.khurana.nikhil.list1;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity {
ListView lv;
TextView tv1, tv2;
View v1;
public String[] s = {"nikhil", "mukul", "kunal"};
public int[] img = {R.drawable.rty, R.drawable.sf, R.drawable.rty};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView lv = (ListView) findViewById(R.id.listView);
CustomAdapter cad = new CustomAdapter(MainActivity.this, s, img);
lv.setAdapter(cad);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent,View v,int position,long id)
{
Toast.makeText(MainActivity.this,"You clicked "+s[position],Toast.LENGTH_SHORT).show();
}
});
}
}
Here is CustomAdapter.java
package com.khurana.nikhil.list1;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class CustomAdapter extends ArrayAdapter<String>{
Context c1;
String s1[];
int s2[];
CustomAdapter(Context c,String s[],int s3[])
{
super(c,R.layout.tcustom,s);
this.c1=c;
this.s1=s;
this.s2=s3;
}
public View getView(int position,View v,ViewGroup parent)
{
LayoutInflater li=(LayoutInflater) c1.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v=li.inflate(R.layout.tcustom,null);
TextView tv=(TextView)v.findViewById(R.id.textView);
ImageView im=(ImageView)v.findViewById(R.id.imageview);
tv.setText(s1[position]);
im.setImageResource(s2[position]);
Button bt=(Button)v.findViewById(R.id.button);
return v;
}
}
((LinearLayout)yourView.getParent()).removeView(yourView);
or you can call from the layout directly
yourRelativeLayout.removeView(yourView)
I would recommend to use an ArrayList instead of a String[] in your Adapter class. It makes it a lot easier to delete or edit a View and the associated data behind it. I used this post to convert your String[] to an ArrayList, delete the item and convert back to String[].
This should work on button click:
In your Adapter class:
public View getView(int position,View v,ViewGroup parent)
{
LayoutInflater li=(LayoutInflater) c1.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v=li.inflate(R.layout.tcustom,null);
TextView tv=(TextView)v.findViewById(R.id.textView);
ImageView im=(ImageView)v.findViewById(R.id.imageview);
tv.setText(s1[position]);
im.setImageResource(s2[position]);
Button bt=(Button)v.findViewById(R.id.button);
bt.setTag(position); //important so we know which item to delete on button click
bt.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
int positionToRemove = v.getTag(); //get the position of the view to delete stored in the tag
removeItem(positionToRemove); //remove the item
}
});
return v;
}
public void removeItem(int position){
//convert array to ArrayList, delete item and convert back to array
ArrayList<String> a = new ArrayList<>(Arrays.asList(s1));
a.remove(i);
strings = new String[a.size()];
s1= a.toArray(strings);
notifyDataSetChanged(); //refresh your listview based on new data
}
#Override
public int getCount() {
return s1.length;
}
#Override
public String getItem(int position) {
return s1[position];
}
View visibility to GONE will not delete your view from memory as well. Please be specific, do you want to retain your view for future?
If you are working in a listview you should call notifyDataSetChanged() the adapter. your getView() method can be like:
action on button can be like this
Button bt=(Button)v.findViewById(R.id.button);
bt.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
s1 = ArrayUtils.remove(s1, position);
s2 = ArrayUtils.remove(s2, position);
notifyDataSetChanged();
}
});
If you want the view to disappear:
yourView.setVisibility(View.GONE);
EDIT: To get the parent view of the button: Android: Making changes to a button's parent view

Fill a GrindView with images taken from Database

i really need your help to solve a problem that might appear stupid for a lot of you.
I need to create a simple Grindview and fill it with images. I tried the sample code provided by the android developers site and it works nicely.
The problem is that the sample code provides images from drawable. I need to fill it with bitmaps that are stored in my sqlite Db as BLOB.
The db is tested and working, and i'm able to obtain the bitmap from the BLOB without problem.
In my code, when the activity starts, nothing happens and i get a white screen without images. I spent many hours on this, i hope that you can give me some tips!!! Thank you in advance for the replies!!! :D
This is my class code:
package cover.me;
import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import cover.me.Game.SimulationView.Cursor;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
public class Gallery extends Activity{
private LinearLayout myGallery;
private android.database.Cursor cursor;
private DbAdapter MyDb;
private int x,y;
private Display display;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gallery);
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(new ImageAdapter(this));
}
public class ImageAdapter extends BaseAdapter{
private Context mContext;
private DbAdapter MyDb;
private int Counter;
private ArrayList<Bitmap> Images = new ArrayList<Bitmap>();
private boolean ImagesLoaded = false;
public ImageAdapter(Context c){
mContext = c;
}
public int getCount() {
return 0;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent){
if(ImagesLoaded == false){ //Add bitmap to Images ArrayList the first time that getView is called
MyDb = new DbAdapter(Gallery.this);
MyDb.open();
cursor = MyDb.fetchAllLevels();
cursor.moveToFirst();
for(int i=0;i<cursor.getCount()-1;i++){
byte[] image = cursor.getBlob(cursor.getColumnIndex(DbAdapter.LvL_Bitmap));
ByteArrayInputStream inputStream = new ByteArrayInputStream(image);
Bitmap mBitmap = BitmapFactory.decodeStream(inputStream);
Images.add(mBitmap);
cursor.moveToNext();
}
cursor.close();
MyDb.close();
ImagesLoaded = true;
}
ImageView imageView;
if (convertView == null){
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
}
else{
imageView = (ImageView) convertView;
}
imageView.setImageBitmap(Images.get(Counter));
Counter++;
return imageView;
}
}
}
And here the XML
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>
This is my first question here on StackOverflow, so give me some tips if i did something wrong with my question!!! Thank you!
This is an old question but it hasn't been answered yet. I believe your problem is that you are returning 0 in your getCount method. I was working on a previous project that is very similar to this one and found this error in mine. getCount needs to return the total number of entries you are wanting to view.
public int getCount() {
return 0; //Needs to return something other than zero
}

Out of MemoryError when creating gallery on android

I am getting this error while creating an android gallery in eclipse. When I add only two images, it runs fine but when i add more images to gallery, it gives this error. Any help would be appreciated!
package com.hospital;
import com.hospital.R;
import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public class myGallery extends Activity {
private final Integer[] pic = {
R.drawable.sample_1,
R.drawable.sample_2,
R.drawable.sample_3
};
ImageView imageview;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gallery);
Gallery gallery = (Gallery)findViewById(R.id.pics);
gallery.setAdapter(new ImageAdapter(this));
imageview = (ImageView)findViewById(R.id.ImageView01);
gallery.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView <?> arg0, View arg1, int arg2, long arg3) {
Toast.makeText(myGallery.this, "" + arg0, Toast.LENGTH_SHORT).show();
imageview.setImageResource(pic[arg2]);
}
});
registerForContextMenu(gallery);
}
public class ImageAdapter extends BaseAdapter {
private final int mGalleryItemBackground;
private final Context mContext;
private final Integer[] pic = {
R.drawable.sample_1,
R.drawable.sample_2,
R.drawable.sample_3
};
public ImageAdapter(Context c) {
mContext = c;
TypedArray attr = c.obtainStyledAttributes(R.styleable.photoGallery);
mGalleryItemBackground = attr.getResourceId(
R.styleable.photoGallery_android_galleryItemBackground, 1);
attr.recycle();
}
public int getCount() {
return pic.length;
}
public Object getItem(int arg0) {
return arg0;
}
public long getItemId(int arg0) {
return arg0;
}
public View getView(int arg0, View arg1, ViewGroup arg2) {
ImageView imageView = new ImageView(mContext);
imageView.setImageResource(pic[arg0]);
imageView.setLayoutParams(new Gallery.LayoutParams(150, 100));
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageView.setBackgroundResource(mGalleryItemBackground);
return imageView;
}
}
}
OutOfMemory is a usual error coming when using large number of bitmaps is used.The only way to reduce the error is to Call System.gc();.System.gc() in your code the Java VM may or may not decide at runtime to do a garbage collection at that point. Try calling "Bitmap".recycle() on your bitmaps after you finish your business with them. This will help you to reduce this error to the most.
Google has provided the lessions to deal with the issue you are facing you can visit it in the following link.
http://developer.android.com/training/displaying-bitmaps/process-bitmap.html
Hope this helps.

Categories

Resources