Log.i("getVIEw()","GETTING VIEW_position[" + String.valueOf(position) + "]" + (convertVIEw != null?convertVIEw.toString():"null"));
启动我的应用程序后,我得到这样的日志:
02-09 14:34:56.900: INFO/getVIEw()(388): GETTING VIEW_position[0]null02-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]null02-09 14:34:57.400: INFO/getVIEw()(388): GETTING VIEW_position[2]null02-09 14:34:57.510: INFO/getVIEw()(388): GETTING VIEW_position[3]null02-09 14:34:57.620: INFO/getVIEw()(388): GETTING VIEW_position[4]null02-09 14:34:57.720: INFO/getVIEw()(388): GETTING VIEW_position[5]null02-09 14:34:57.840: INFO/getVIEw()(388): GETTING VIEW_position[6]null02-09 14:34:57.930: INFO/getVIEw()(388): GETTING VIEW_position[7]null02-09 14:34:58.273: DEBUG/dalvikvm(388): GC freed 3530 objects / 322744 bytes in 270ms02-09 14:34:58.280: INFO/getVIEw()(388): GETTING VIEW_position[8]null02-09 14:34:58.300: INFO/getVIEw()(388): GETTING VIEW_position[9]null02-09 14:34:58.320: INFO/getVIEw()(388): GETTING VIEW_position[10]null02-09 14:34:58.340: INFO/getVIEw()(388): GETTING VIEW_position[11]null02-09 14:34:58.360: INFO/getVIEw()(388): GETTING VIEW_position[12]null02-09 14:34:58.380: INFO/getVIEw()(388): GETTING VIEW_position[13]null02-09 14:34:58.400: INFO/getVIEw()(388): GETTING VIEW_position[14]null02-09 14:34:59.220: INFO/getVIEw()(388): GETTING VIEW_position[0]null02-09 14:34:59.490: INFO/getVIEw()(388): GETTING VIEW_position[0]androID.Widget.FrameLayout@44c69ef0
我也是红色this的帖子关于这样一个问题.但是我的GrIDVIEw的XML描述中的高度设置为填充父项:
<?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" />
最后删除所有疑问,这里是我的适配器代码:
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); 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; } }
我希望有人会回答我的问题,并帮助我解决这个问题.
等待你的建议亚历克斯.
解决方法 如果相当清楚,我认为这个链接的回应There is absolutely no guarantee on
the number of times getVIEw() will be
invoked for any given position
现在这个意思也暗示你不应该使用wrap_content
usually occurs with Lists and grIDs
that have a height set to wrap_content
但这并不意味着在其他情况下不会发生.这个BUG被关闭为“WorkingAsIntended”,所以我不认为你可以做太多.这只是可能发生的事情.
总结以上是内存溢出为你收集整理的android – 在GridView中多次调用getView()全部内容,希望文章能够帮你解决android – 在GridView中多次调用getView()所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)