有时候会遇到一些工作计划的需求,大多数工作计划都会有统一的模板,即计划内容分类是一致的。
比如说周计划管理:每周都有7天,对于我们来说就会有两个方案:1、画7个相同布局 2、动态生成7个布局
之前有想过直接用ListView来做,其实也是可以的,但是涉及到一些复杂的需求,例如I:tem的子控件加点击事件,并通过该事件引发一系列操作刷新此Item内容,获取输入框内部内容等,ListView的劣势就体现出来,ListView是复用同一个ItemView,刷新的同时position的控制问题总是一个BUG。所以没有考虑用ListView来做。
借用ListView的思想,我们是不是可以创建一个满足工作计划复杂性的View,并动态获取创建,赋予丰富的ID属性,以及点击事件,答案是可以的。
下面是关键代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/month_mactivitys_ll_province"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:background="@color/white"
android:padding="10dp" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="6"
android:text="省份:"
android:textColor="@color/unread"
android:textSize="@dimen/main_text_size" />
<TextView
android:id="@+id/month_mactivitys_tv_province"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="请选择省份"
android:textColor="@color/unread"
android:textSize="@dimen/main_text_size" />
<!-- <requestFocus /> -->
</LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_marginLeft="5dp"
android:background="@color/listview_divider" />
<LinearLayout
android:id="@+id/month_mactivitys_ll_startTime"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/white"
android:padding="10dp" >
<TextView
android:layout_width="wrap_content"