使用系统自带CheckBox实现单选效果的2个线性布局切换
来源:互联网 发布:网络新词及解释 编辑:程序博客网 时间:2024/05/18 01:10
public class MainActivity extends Activity {
CheckBox checkbox1, checkbox2;
LinearLayout babyInfo, baomuInfo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
babyInfo = (LinearLayout) this.findViewById(R.id.babyInfo);
baomuInfo = (LinearLayout) this.findViewById(R.id.baomuInfo);
checkbox1 = (CheckBox) findViewById(R.id.checkBox1);
checkbox2 = (CheckBox) findViewById(R.id.checkBox2);
checkbox1.setOnCheckedChangeListener(new OnCheckedChangeListener() {//检查变化监听
@Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
// TODO Auto-generated method stub
if (checkbox1.isChecked()) {
resetStatus();
checkbox1.setChecked(true);
babyInfo.setVisibility(View.VISIBLE);
}
}
});
checkbox2.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
// TODO Auto-generated method stub
if (checkbox2.isChecked()) {
resetStatus();
checkbox2.setChecked(true);
baomuInfo.setVisibility(View.VISIBLE);
}
}
});
babyInfo.setVisibility(View.VISIBLE);
}
//将重置布局状态
protected void resetStatus() {
// TODO Auto-generated method stub
checkbox2.setChecked(false);
checkbox1.setChecked(false);
babyInfo.setVisibility(View.GONE);
baomuInfo.setVisibility(View.GONE);
}
}
布局layout代码如下所示:
<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:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="7dip"
android:paddingLeft="10dip"
android:paddingRight="10dip"
android:paddingTop="10dip"
android:text="类型选择: "
android:textColor="@color/blue"
android:textSize="14sp" />
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="宝宝护理" />
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="宝妈护理" />
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:background="@color/blue"
android:orientation="vertical" >
</View>
<LinearLayout
android:id="@+id/babyInfo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="宝宝喂养:指导科学母乳喂养或根据情况进行人工喂养,并记录每次喂养时间与奶量" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="测量体温:每日进行一次体温测量并记录" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="观测呼吸情况:每日记录宝宝1分钟呼吸次数" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="检查尿布:每两个小时常规性检查、更换尿布检查大小便并记录" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="调整卧姿:每两个小时调整一次" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="洗澡时间:每日傍晚给宝宝宝洗澡,包括头部、眼耳鼻清洁" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="脐部护理:宝贝肚脐掉落之前每日用碘伏棉棒消毒清洁" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="抚触:每日宝贝洗澡以前进行抚触" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="婴儿用品消毒:奶瓶、衣物等婴儿常用品清洗高温消毒" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="婴儿床整理消毒:每日整理婴儿床并用酒精擦拭消毒" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="体重身高测量:每周进行一次体重与身高测量并记录" />
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:background="@color/blue"
android:orientation="vertical" >
</View>
</LinearLayout>
<LinearLayout
android:id="@+id/baomuInfo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="产妇生活护理:科学指导母乳喂养,人工喂养每2~3小时喂养一次 " />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="乳房护理:乳房按摩 疏通 " />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="宝妈擦身:帮助产妇擦洗身体 " />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="营养:配餐指导" />
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:background="@color/blue"
android:orientation="vertical" >
</View>
</LinearLayout>
</LinearLayout>
- 使用系统自带CheckBox实现单选效果的2个线性布局切换
- 多个checkbox实现单选的checkbox
- Android ViewFlipper实现多个布局手势切换的效果
- 使用checkbox实现单选效果 (模拟radio)
- 使用线性布局LinearLayout实现类似计算器的效果
- Android ListView带CheckBox实现单选
- easyui tree带checkbox实现单选
- ios 系统 自带动画效果使用
- checkbox实现单选按钮效果
- input:checkbox多选框实现单选效果
- checkbox 实现单选效果(html)
- 用CheckBox实现ListView单选效果
- ListView+CheckBox实现单选效果
- checkbox多选框实现单选效果
- RecyclerView之CheckBox实现单选效果
- android自带抽屉效果的实现
- GridView实现checkbox效果(单选效果)
- 使用系统自带的 UIRefreshControl 实现下拉刷新
- ArcSDE空间数据库中SDE用户使用探讨
- ReactNative之开发Mac环境配置
- c#控件说明
- 枚举类
- Educational Codeforces Round 5-A. Comparing Two Long Integers(模拟)
- 使用系统自带CheckBox实现单选效果的2个线性布局切换
- Swift 懒加载
- 上下拉电阻的设计
- Ajax等待返回结果时,弹出一个友好的等待提示
- extjs 架构图
- Android studio 项目没有错误,运行按钮为灰色无法运行,rebuild 和 clean 都没有用
- 代码控制IE11以兼容IE8的模式启动
- Java JSON技术框架选型与实例
- Activity四种启动模式