今天跟大家简单的说说,我们在开发中有时候会遇到listview中有checkbox,由于我们重用了convertView,但是一些错误问题!这种解决思路,是我的之前一个朋友跟我说的,他以前工作中,遇到这个问题,他的一种解决思路,现在分享给大家
效果图:
接下来简单的说说listview一些优化:
1、布局文件的android:layout_width,android:layout_height 设置要非“wrap_content”,如果这里不这么设置的话,getView将会被重复执行3~4次
2、给convertView设置Tag,为了是减少findViewById
布局xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout