In Activity I have 1 Fragment with ListView. In ListView photos. When you change tabs in the Activity, the content of the ListView (which is in Fragment) changes. Photos remain in memory and an OutOfMemory error occurs. I need your help, thank you.

public class MySimpleCursorAdapter extends SimpleCursorAdapter { private LayoutInflater mLayoutInflater; private Context context; private int layout; private class ViewHolder { ImageView mphoto; TextView id; TextView title; ViewHolder(View v) { id = (TextView) v.findViewById(R.id.id); mphoto = (ImageView) v.findViewById(R.id.mphoto); title = (TextView) v.findViewById(R.id.title); } } public MySimpleCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int i) { super(context, layout, c, from, to); this.context = context; this.layout = layout; mLayoutInflater = LayoutInflater.from(context); } @Override public View newView(Context ctx, Cursor cursor, ViewGroup parent) { View vView = mLayoutInflater.inflate(layout, parent, false); vView.setTag( new ViewHolder(vView) ); return vView; } @Override public void bindView(View v, Context ctx, Cursor c) { int index_id = c.getColumnIndex(DataBaseHelper.C_ID); int index_photo = c.getColumnIndex(DataBaseHelper.C_MPHOTO); int index_title = c.getColumnIndex(DataBaseHelper.C_TITLE); String string_photo = c.getString(index_photo); String string_id = c.getString(index_id); String string_title = c.getString(index_title); ViewHolder vh = (ViewHolder) v.getTag(); vh.mphoto.setImageURI(Uri.parse("android.resource://com.aaa.aaaaa/drawable/" + string_photo)); vh.id.setText(string_id); vh.title.setText(string_title); } } 
  • one
    What tabs are we talking about? Show the adapter code ListView - miha_dev
  • Added adapter, and tabs - TabLayout - Vlad
  • Those. each tab has its own ListView ? or in each different? if different, they have the same adapters? - miha_dev
  • the adapter is the same, and the ListView is the same, depending on the tab (there are 8 of them) the pictures in the ListView change. - Vlad

1 answer 1

Use https://github.com/nostra13/Android-Universal-Image-Loader . You can customize how you want and need.