首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

android 承袭BaseAdapter,自定义的适配器,getView方法执行多组循环解决方式

2012-07-16 
android 继承BaseAdapter,自定义的适配器,getView方法执行多组循环解决方式1.如果Activity继承ListActivit

android 继承BaseAdapter,自定义的适配器,getView方法执行多组循环解决方式
1.如果Activity继承ListActivity,不自定义布局文件,直接使用android默认的ListView布局文件.不会出现getView()方法执行多组循环.
android默认的ListView布局文件如下:
<ListView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:drawSelectorOnTop="false"
    />

2.如果要使用自定义的ListView布局文件.需要注意的ListView的高度属性应该设置成fill_parent,如果ListView有父节点,那么父节点的高度属性也应该设置成fill_parent

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
>
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="none"
android:cacheColorHint="@android:color/transparent"
android:dividerHeight="1px"
android:divider="@color/list_dashed" >
</ListView>
</LinearLayout>

android在画布局的时候,会调用measure来确定View大小.导致getView执行多组相同的循环

热点排行