Android : Android ImageView Outof memory

on Sunday, March 8, 2015


This is my code, It response Outofmemory error on samsung mobile! I searched very much in google but not answered. When Showing Image in list show force close.



public class CustomList extends ArrayAdapter<String>{

private final Activity context;
private final String[] web;
private final String[] imageId;

public CustomList(Activity context,String[] web,String[] img) {
super(context, R.layout.tag_list_item, web);
this.context = context;
this.web = web;
this.imageId = img;
}

@SuppressLint({ "ViewHolder", "InflateParams" })
@Override
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View rowView= inflater.inflate(R.layout.tag_list_item, null, true);
TextView txtTitle = (TextView) rowView.findViewById(R.id.txt);

ImageView imageView = (ImageView) rowView.findViewById(R.id.img);
txtTitle.setText(web[position]);
try{
Resources resources = context.getResources();

final int resourceId = resources.getIdentifier("cat_"+imageId[position].trim().toString(), "drawable",
context.getPackageName());
//resources.getDrawable(resourceId);
imageView.setImageDrawable(resources.getDrawable(resourceId));
}catch(Exception e){
Toast.makeText(getApplicationContext(), e.toString()+" "+imageId[position].trim().toString(), Toast.LENGTH_LONG).show();
}
return rowView;
}

}

0 comments:

Post a Comment