我有一个列表视图,我从网上加载位图..但现在的问题是我有1000项在ListView因此,它是导致我内存不足的错误..我已经使用了图像缓存也。 。
Answer 1:
我想使用的任何低于人会解决你的问题
懒列表
通用ImageLoader的
Answer 2:
试试下面的代码:
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;
}
};
}
Answer 3:
您也可以尝试通过缩放图像下尽可能减少内存使用情况。 这里是如何做到这一点的例子。
文章来源: Avoiding out of memory error in loading bitmap in listview