日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > Android >内容正文

Android

android复选按钮,Android的复选框的详细开发案例分析

發(fā)布時(shí)間:2023/12/4 Android 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android复选按钮,Android的复选框的详细开发案例分析 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

在本教程中,我們將向您展示如何創(chuàng)建XML文件中的3個(gè)復(fù)選框,并論證了聽者的使用檢查–選中或取消選中復(fù)選框的狀態(tài)。

P.S這個(gè)項(xiàng)目是在Eclipse 3.7開發(fā),并與Android 2.3.3測(cè)試。

1。自定義字符串

Open “res/values/strings.xml” file, add some user-defined string.

res/values/strings.xml文件:

<resources><string?姓名=“hello“>Hello?World,?MyAndroidAppActivity!</string>

<string?姓名=“app_name“>MyAndroidApp</string>

<string?姓名=“chk_ios“>IPhone</string>

<string?姓名=“chk_android“>Android</string>

<string?姓名=“chk_windows“>Windows?Mobile</string>

<string?姓名=“btn_display“>Display</string>

</resources>

2。復(fù)選框

Open “res/layout/ main.xml” file, add 3 “復(fù)選框” and a button, inside the 線性布局.

文件:res/layout/ main.xml

<LinearLayout xmlns:android=“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>

使復(fù)選框默認(rèn)被選中

Put android:checked="true" 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”.

如果按鈕被點(diǎn)擊時(shí),顯示一個(gè)浮動(dòng)框和復(fù)選框的狀態(tài)顯示。

文件:myandroidappactivity.java

旅行包 com。mkyong。android

進(jìn)口 android。app。Activity

進(jìn)口 android。os。Bundle

進(jìn)口 android。view。View

進(jìn)口 android。view。View。OnClickListener

進(jìn)口 android。widget。Button

進(jìn)口 android。widget。CheckBox

進(jìn)口 android。widget。Toast

公共 類 myandroidappactivity 延伸 活動(dòng) {

私人 CheckBox chkIos, chkAndroid, chkWindows

私人 Button btnDisplay

@Override

公共 無效 創(chuàng)建時(shí)的回調(diào)函數(shù)(Bundle savedInstanceState) {超級(jí)的。創(chuàng)建時(shí)的回調(diào)函數(shù)(savedInstanceState)

setContentView(R。layout。main)

addlisteneronchkios()

addlisteneronbutton()

}

公共 無效 addlisteneronchkios() {chkIos?=?(CheckBox)?findViewById(R。id。chkIos)

chkIos。setlistener(新?listener()?{

@Override

公共?無效?(View?v)?{

/?/是chkios檢查嗎?

如果?(((CheckBox)?v)。把關(guān)())?{

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?/運(yùn)行

@Override

公共?無效?(View?v)?{

StringBuffer?result?=?新?StringBuffer()

result。追加(“iPhone檢查:”)。追加(chkIos。把關(guān)())

result。追加(“nandroid檢查:”)。追加(chkAndroid。把關(guān)())

result。追加(“移動(dòng)nwindows檢查:\”)。追加(chkWindows。把關(guān)())

Toast。maketext(MyAndroidAppActivity。這,?result。toString(),

Toast.LENGTH_LONG).show();

}

});

}

}

4. Demo

Run the application.

1. Result :

2. If “IPhone” is checked :

3. Checked “IPhone” and “Windows Mobile”, later, click on the “display” button :

總結(jié)

以上是生活随笔為你收集整理的android复选按钮,Android的复选框的详细开发案例分析的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。