android - GridView inside ListView giving OutOfMemoryError -
i creating , gallery in images grouped date. using listview has gridview @ each row. when gridview of row contains large amount of images 2000, app crashed giving outofmemoryerror. how fix ?
adapter of listview:
public class myadapter extends baseadapter { private arraylist<string> itemdetailsrraylist; context mcontext; private layoutinflater l_inflater; public myadapter(context context, arraylist<string> results) { itemdetailsrraylist = results; l_inflater = layoutinflater.from(context); mcontext = context; } public int getcount() { return itemdetailsrraylist.size(); } public object getitem(int position) { return itemdetailsrraylist.get(position); } public long getitemid(int position) { return position; } public view getview(int position, view convertview, viewgroup parent) { viewholder holder; if (convertview == null) { convertview = l_inflater.inflate(r.layout.settinglayout, null); holder = new viewholder(); holder.mygrid = (mygridview) convertview .findviewbyid(r.id.grid); convertview.settag(holder); } else { holder = (viewholder) convertview.gettag(); } holder.mygrid.setadapter(new imageadapter(itemdetailsrraylist.get(position))); return convertview; } static class viewholder { mygridview mygrid; } }
my custom gridview class
public class mygridview extends gridview{ public mygridview(context context) { super(context); } boolean expanded = false; public boolean isexpanded() { return expanded; } public void setexpanded(boolean expanded) { this.expanded = expanded; } @override public void onmeasure(int widthmeasurespec, int heightmeasurespec) { // hack! take android! if (isexpanded()) { // calculate entire height providing large height hint. // not use highest 2 bits of integer; // reserved measurespec mode. int expandspec = measurespec.makemeasurespec(integer.max_value >> 2, measurespec.at_most); super.onmeasure(widthmeasurespec, expandspec); layoutparams params = (layoutparams) getlayoutparams(); params.height = getmeasuredheight(); } else { super.onmeasure(widthmeasurespec, heightmeasurespec); } }
}
Comments
Post a Comment