0

I am having an listview and i am loading bitmaps in it from the web .. but now the problem is i am having 1000 item in the listview so, it is causing me out of memory error.. i have used the image caching also..

Sandeep Dhull
  • 1,560
  • 1
  • 17
  • 29

3 Answers3

2

I think using any one of the below will solve your problem

Lazy List

Universal ImageLoader

Ram kiran
  • 20,129
  • 14
  • 55
  • 74
1

try the following code:

   public class ListFivePictureNameDetailsPassFail extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setListAdapter(new StudentListAdapter(this));
}

private class StudentListAdapter extends BaseAdapter {
    private Context mContext;
    private String[] mStudents = { "DurgaPrasad", "Raghu", "Vivek",
            "Satish", "Naga Jyothi", "Vardhika", "Nikhil" };
    private String[] mDetailsStudent = { "Details of DurgaPrasad",
            "Details of  Raghu This row is not created using java",
            "Details of Vivek", "Details of Satish",
            "Details of Naga Jyothi", "Details of Vardhika",
            "Details of Nikhil" };

    public StudentListAdapter(Context context) {
        mContext = context;
    }

    public int getCount() {
        return mStudents.length;
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        if (v == null) {
            System.out.println("111111111111 : "+position);
            LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            /*if (position == 0) {
                System.out.println("111111111111 : "+position);
                v = vi.inflate(R.layout.studentdetailsrow, null);
                System.out.println("111111111111 : "+position);
            } else*/
                v = vi.inflate(R.layout.studentdetailsrowother, null);
        }

        ImageView iv = (ImageView) v.findViewById(R.id.icon);
        ImageView iv2 = (ImageView) v.findViewById(R.id.icon2);
        if (position == 0) {
            iv.setImageResource(R.drawable.newicon);
            iv2.setImageResource(R.drawable.icon);
        } else {
            iv.setImageResource(R.drawable.newicon);
            iv2.setImageResource(R.drawable.icon);
        }

        TextView tvname = (TextView) v.findViewById(R.id.stuname);
        TextView tvdetail = (TextView) v.findViewById(R.id.studetail);
        tvname.setText(mStudents[position]);
        tvdetail.setText(mDetailsStudent[position]);
        return v;
    }
};

   }
G M Ramesh
  • 3,264
  • 9
  • 32
  • 53
0

You can also try to minimize the memory usage by scaling the images down as much as possible. Here is an example on how to do that.

Community
  • 1
  • 1
SimonSays
  • 10,366
  • 5
  • 38
  • 49