炫酷的企业网站模板,一体化企业管理软件,自学软件开发从哪开始,加强网站建设 基本措施在本教程中#xff0c;我们将向您展示如何创建XML文件中的3个复选框#xff0c;并论证了听者的使用检查–选中或取消选中复选框的状态。P.S这个项目是在Eclipse 3.7开发#xff0c;并与Android 2.3.3测试。1。自定义字符串Open “res/values/strings.xml” file, add some u…在本教程中我们将向您展示如何创建XML文件中的3个复选框并论证了听者的使用检查–选中或取消选中复选框的状态。P.S这个项目是在Eclipse 3.7开发并与Android 2.3.3测试。1。自定义字符串Open “res/values/strings.xml” file, add some user-defined string.res/values/strings.xml文件resourcesstring 姓名“hello“Hello World, MyAndroidAppActivity!stringstring 姓名“app_name“MyAndroidAppstringstring 姓名“chk_ios“IPhonestringstring 姓名“chk_android“Androidstringstring 姓名“chk_windows“Windows Mobilestringstring 姓名“btn_display“Displaystringresources2。复选框Open “res/layout/ main.xml” file, add 3 “复选框” and a button, inside the 线性布局.文件res/layout/ main.xmlLinearLayout xmlnsandroid“http://schemas.android.com/apk/res/android“安卓layout_width“fill_parent“安卓layout_height“fill_parent“安卓orientation“vertical“ CheckBox安卓id“id/chkIos“安卓layout_width“wrap_content“安卓layout_height“wrap_content“安卓text“string/chk_ios“ CheckBox安卓id“id/chkAndroid“安卓layout_width“wrap_content“安卓layout_height“wrap_content“安卓text“string/chk_android“安卓checked“true“ CheckBox安卓id“id/chkWindows“安卓layout_width“wrap_content“安卓layout_height“wrap_content“安卓text“string/chk_windows“ Button安卓id“id/btnDisplay“安卓layout_width“wrap_content“安卓layout_height“wrap_content“安卓text“string/btn_display“ LinearLayout使复选框默认被选中Put android:checkedtrue inside checkbox element to make it checked bu default. In this case, “Android” option is checked by default.三.代码代码Attach listeners inside your activity “onCreate()” method, to monitor following events :If checkbox id : “chkios” is checked, display a floating box with message “Bro, try Android”.如果按钮被点击时显示一个浮动框和复选框的状态显示。文件myandroidappactivity.java旅行包 com。mkyong。android进口 android。app。Activity进口 android。os。Bundle进口 android。view。View进口 android。view。View。OnClickListener进口 android。widget。Button进口 android。widget。CheckBox进口 android。widget。Toast公共 类 myandroidappactivity 延伸 活动 {私人 CheckBox chkIos chkAndroid chkWindows私人 Button btnDisplayOverride公共 无效 创建时的回调函数(Bundle savedInstanceState) {超级的。创建时的回调函数(savedInstanceState)setContentView(R。layout。main)addlisteneronchkios()addlisteneronbutton()}公共 无效 addlisteneronchkios() {chkIos (CheckBox) findViewById(R。id。chkIos)chkIos。setlistener(新 listener() {Override公共 无效 (View v) {/ /是chkios检查吗如果 (((CheckBox) v)。把关()) {Toast。maketext(MyAndroidAppActivity。这“兄弟尝试Android)” Toast。LENGTH_LONG)。商展()}}})}公共 无效 addlisteneronbutton() {chkIos (CheckBox) findViewById(R。id。chkIos)chkAndroid (CheckBox) findViewById(R。id。chkAndroid)chkWindows (CheckBox) findViewById(R。id。chkWindows)btnDisplay (Button) findViewById(R。id。btnDisplay)btnDisplay。setlistener(新 listener() {clicked button is when /运行Override公共 无效 (View v) {StringBuffer result 新 StringBuffer()result。追加(“iPhone检查”)。追加(chkIos。把关())result。追加(“nandroid检查”)。追加(chkAndroid。把关())result。追加(“移动nwindows检查\”)。追加(chkWindows。把关())Toast。maketext(MyAndroidAppActivity。这 result。toString(),Toast.LENGTH_LONG).show();}});}}4. DemoRun the application.1. Result :2. If “IPhone” is checked :3. Checked “IPhone” and “Windows Mobile”, later, click on the “display” button :