android中控件Checkbox复选框的使用
来源:互联网 发布:华中地区数据科学会议 编辑:程序博客网 时间:2024/04/28 05:03
在layout的activity_main.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="请选择爱好:" />
<CheckBox
android:id="@+id/eat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="吃饭"
/>
<CheckBox
android:id="@+id/sleep"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="睡觉"
/>
<CheckBox
android:id="@+id/chat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="聊天"
/>
<CheckBox
android:id="@+id/sing"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="唱歌"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="click"
android:text="查看" >
</Button>
在activity_main.java中
public class MainActivity extends Activity {private CheckBox eat ;private CheckBox sleep ;private CheckBox chat ;private CheckBox sing ;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);eat = (CheckBox) findViewById(R.id.eat) ;sleep = (CheckBox) findViewById(R.id.sleep) ;chat = (CheckBox) findViewById(R.id.chat) ;sing = (CheckBox) findViewById(R.id.sing) ;}public void click(View view){StringBuilder sb = new StringBuilder() ;if(eat.isChecked()){sb.append(eat.getText() + ",") ;}if(sleep.isChecked()){sb.append(sleep.getText() + ",") ;}if(chat.isChecked()){sb.append(chat.getText() + ",") ;}if(sing.isChecked()){sb.append(sing.getText() + ",") ;}if(TextUtils.isEmpty(sb.toString())){Toast.makeText(this, "你没有选择任何爱好", 0).show() ;}else{Toast.makeText(this, "你选择的爱好是:" + sb.substring(0, sb.length()-1), 0).show() ;}}}
0 0
- android中控件Checkbox复选框的使用
- Android的UI组件复选框控件CheckBox
- android复选框控件——CheckBox
- Android控件——复选框CheckBox
- Android的CheckBox复选框
- 复选框CheckBox的使用
- 复选框checkbox控件
- Android中复选框CheckBox的初始化细节
- 安卓控件使用系列12:CheckBox复选框控件的使用
- Android中CheckBox复选框操作
- android 中 CheckBox 复选框操作
- Android中CheckBox复选框操作
- Android之复选框CheckBox使用
- 【Android 开发】:UI控件之复选框控件 CheckBox 的使用方法
- Android 复选框CheckBox
- Android之CheckBox复选框控件使用inelayout.xml Xml代码
- Android 自定义CheckBoxPreference的CheckBox复选框
- Android 自定义CheckBoxPreference的CheckBox复选框
- UITextField的leftView不贴边处理
- 黑马程序员——Java基础---反射
- dll项目中_declspec(dllimport)和_declspec(export)使用
- OJ第三批——Problem R:P3 数钱是件愉快的事
- LeetCode Gray Code
- android中控件Checkbox复选框的使用
- c++中map
- LeetCode-208 Implement Trie (Prefix Tree)
- 递归实现全排列,字典序法实现全排列
- 29Divide Two Integers
- Android Studio中常用设置与快捷键(私人珍藏,Eclipse转AS必看)
- LeetCode_Sum Root to Leaf Numbers
- Linux的启动SD卡的格式化方法 此博文包含图片(2010-07-11 21:20:55)
- iOS多线程编程之NSThread的使用