android - Multiple calling of getView() in GridView -
my activity consists of gridview holds 40+ elements. after starting activity user see maximum 15 items (3 rows, 5 items in each row). wrote in getview() body pass logcat number of getting view:
log.i("getview()", "getting view_position[" + string.valueof(position) + "]" + (convertview != null?convertview.tostring():"null"));
after launching app such log:
02-09 14:34:56.900: info/getview()(388): getting view_position[0]null 02-09 14:34:57.300: info/getview()(388): getting view_position[0]android.widget.framelayout@44c7a9c0 02-09 14:34:57.300: info/getview()(388): getting view_position[1]null 02-09 14:34:57.400: info/getview()(388): getting view_position[2]null 02-09 14:34:57.510: info/getview()(388): getting view_position[3]null 02-09 14:34:57.620: info/getview()(388): getting view_position[4]null 02-09 14:34:57.720: info/getview()(388): getting view_position[5]null 02-09 14:34:57.840: info/getview()(388): getting view_position[6]null 02-09 14:34:57.930: info/getview()(388): getting view_position[7]null 02-09 14:34:58.273: debug/dalvikvm(388): gc freed 3530 objects / 322744 bytes in 270ms 02-09 14:34:58.280: info/getview()(388): getting view_position[8]null 02-09 14:34:58.300: info/getview()(388): getting view_position[9]null 02-09 14:34:58.320: info/getview()(388): getting view_position[10]null 02-09 14:34:58.340: info/getview()(388): getting view_position[11]null 02-09 14:34:58.360: info/getview()(388): getting view_position[12]null 02-09 14:34:58.380: info/getview()(388): getting view_position[13]null 02-09 14:34:58.400: info/getview()(388): getting view_position[14]null 02-09 14:34:59.220: info/getview()(388): getting view_position[0]null 02-09 14:34:59.490: info/getview()(388): getting view_position[0]android.widget.framelayout@44c69ef0
i red this post such kind of issue. gridview's height in xml description set fill parent:
<?xml version="1.0" encoding="utf-8"?> <gridview xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/grid" android:layout_width="fill_parent" android:layout_height="fill_parent" android:numcolumns="auto_fit" android:horizontalspacing="10dp" android:verticalspacing="10dp" android:columnwidth="140dp" android:gravity="center" android:scrollbars="none" />
and remove doubts, here adapter code:
public class imageadapter extends baseadapter { private activity activity; private layoutinflater inflater = null; private arraylist<photo> photoes; public imageadapter(activity a, arraylist<photo> pictures) { photoes = pictures; activity = a; inflater = (layoutinflater)activity.getsystemservice(context.layout_inflater_service); } @override public view getview(int position, view convertview, viewgroup parent) { log.i("getview()", "getting view_position[" + string.valueof(position) + "]" + (convertview != null?convertview.tostring():"null")); view mviewslice = convertview; if(convertview == null) { mviewslice = inflater.inflate(r.layout.photo_preview, null); ((textview) mviewslice.findviewbyid(r.id.name_of_photo)).settext(photoes.get(position).getname()); mviewslice.setpadding(5, 5, 5, 5); mviewslice.setlayoutparams(new gridview.layoutparams(-2, -2)); } return mviewslice; } @override public int getcount() { return photoes.size(); } @override public object getitem(int position) { return photoes.get(position); } @override public long getitemid(int position) { return position; } }
i hope respond @ problem , me solve it.
waiting suggestions. alex.
the response on link if quite clear think
there absolutely no guarantee on number of times getview() invoked given position
now remark implies shouldn't use wrap_content
usually occurs lists , grids have height set wrap_content
but not mean not happen other situations. bug closed "workingasintended", don't think can much. it's can happen.
Comments
Post a Comment