版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/aaa1050070637/article/details/82185042
今天在做一个关于ListView,
发错字item的checkBox的状态老是不对,
debug的时候,发现getview方法整体执行了两遍,再三确认,造成上面问题的答案找到了,就是因为getview方法执行第二遍的时候把状态改回去了。。。
那么这个问题怎么解决呢,我就查看了下listview的源码,发现在listview高度设置为wrap_content的时候,会多次调用getview方法,去计算listview的高度。
我的解决方案如下
<RelativeLayout
android:id="@+id/rl_pop_parent"
android:layout_width="match_parent"
android:layout_height="300dp">
<ListView
android:id="@+id/menulist"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:divider="#696969"
android:dividerHeight="1dip"
android:padding="2dip"
android:scrollbars="none" />
</RelativeLayout>