Android 中 ListView Adapter getView 被多次调用问题 解决方法

执行多次原因是因为每显示一个VIew,它都去测量view的高度,执行measure方法,导致getView执行多次。

解决方法是将 ListView 的 layout_width 设置为 fill_parent,
 <ListView
        android:id="@+id/lv_messages"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/linearLayout1"
        android:cacheColorHint="#0000"
        android:divider="#0000"
        android:dividerHeight="2dp"
        android:listSelector="#0000" >
 </ListView>

把width和height都设置成fill_parent,如果ListView有父布局,也把父布局的width和height设置成fill_parent,这样就成功的解决了自定义适配器getView 执行多次的问题。

posted @ 2015-01-30 11:15  TuWei  阅读(862)  评论(0编辑  收藏  举报