Scroll grid view with plenty amount of local Images make my app crashes in devices have small amount of RAM with message java.lang.OutOfMemoryError or at-least in good performance devices it's scroll very Barely and with lag. I goggled for solution and find some good solutions are exist for remote Images like: Universal-Image-Loader that loading images from web and cashes them and manage scrolling. but I couldn't use that on my case.
this is my adapter that load images:
public class MyAdapter extends ArrayAdapter<StructureCase> {
private LayoutInflater mInflater = null;
public Context context;
public Class distinationActivity = null;
public MyAdapter(Context context, int textViewResourceId, List<StructureCase> objects) {
super(context, textViewResourceId, objects);
mInflater = LayoutInflater.from(context);
// mInflater = (LayoutInflater)G.currentActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public static class ViewHolder {
public ImageView gem_img = null;
public TextView gem_name = null;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder viewHolder;
final View v;
final StructureCase item = getItem(position);
if (convertView == null) {
convertView = this.mInflater.inflate(R.layout.my_grid_list, null);
//mInflater = (LayoutInflater)G.currentActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.my_grid_list, parent, false);
viewHolder = new ViewHolder();
convertView.setTag(viewHolder);
viewHolder.gem_img = (ImageView) convertView.findViewById(R.id.imageView_mygrid_list);
viewHolder.gem_name = (TextView) convertView.findViewById(R.id.textView_mygrid_list);
viewHolder.gem_name.setTypeface(G.typeFacePrs);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.gem_name.setText(item.g_name);
int id = G.currentActivity.getResources().getIdentifier(item.g_image+"_tmb", "drawable", G.currentActivity.getPackageName());
if(id != 0){
Drawable drawable = G.currentActivity.getResources().getDrawable(id);
viewHolder.gem_img.setImageDrawable(drawable);
}else{
viewHolder.gem_img.setImageResource(R.drawable.gem1);
}
viewHolder.gem_img.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(G.currentActivity, GemDetaileActivity.class);
i.putExtra("id", item.g_ID);
i.putExtra("content", item.g_text);
i.putExtra("name", item.g_name);
i.putExtra("name_en", item.g_name_en);
i.putExtra("image", item.g_image);
i.putExtra("image_count", item.g_image_count);
i.putExtra("hadis", item.g_hadis);
i.putExtra("good_for", item.g_good_for);
G.currentActivity.startActivity(i);
G.currentActivity.overridePendingTransition(R.anim.in_left_2_right, R.anim.out_left_2_right);
}
});
return convertView;
}
@Override
public long getItemId(int position) {
return position;
}
}
I think my problem is for pre-Loading all Images and if there is a way to load Drawable to Image view as soon as show it's item in scroll, my problem will solve.
Aucun commentaire:
Enregistrer un commentaire