这几天在做公司的项目,有这样一个需求,就是在listView里,点击item子项的时候需要保持item子项的选中状态,上网搜了一些资料,最后也实现了。现在就记录下来,一方面方便以后自己回顾好复习温故,另外也和大家分享。
不多说了,上代码。先贴xml布局文件的。
不多说了,上代码。先贴xml布局文件的。
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/portalLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<RelativeLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="2"
android:background="#cccccc"
android:orientation="vertical" >
<ListView
android:id="@+id/testModuleListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginTop="100dp" />
</LinearLayout>
item_module.xml