国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android開發之CheckBox的簡單使用與監聽功能示例

2019-12-12 02:22:40
字體:
來源:轉載
供稿:網友

本文實例講述了Android開發之CheckBox的簡單使用與監聽功能。分享給大家供大家參考,具體如下:

activity_main.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="horizontal" >  <CheckBox    android:checked="false"    android:id="@+id/checkBox1"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="足球" /></LinearLayout>

MainActivity.java

package com.example.hello;import android.support.v7.app.ActionBarActivity;import android.os.Bundle;import android.util.Log;import android.view.Menu;import android.view.MenuItem;import android.widget.CheckBox;import android.widget.CompoundButton;import android.widget.CompoundButton.OnCheckedChangeListener;import android.widget.Toast;public class MainActivity extends ActionBarActivity {  private CheckBox checkBox;  @Override  protected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_main);    //初始化    checkBox = (CheckBox) findViewById(R.id.checkBox1);    //通過設置checkbox的監聽事件,判斷checkbox是否被選中    checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {      @Override      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {        // 通過這個方法,來監聽當前的checkbox是否被選中        if (isChecked) {          //獲得checkBox的文本內容          String text = checkBox.getText().toString();          Toast.makeText(MainActivity.this, "111", 1).show();        }      }    });  }}

更多關于Android相關內容感興趣的讀者可查看本站專題:《Android開發入門與進階教程》、《Android調試技巧與常見問題解決方法匯總》、《Android基本組件用法總結》、《Android視圖View技巧總結》、《Android布局layout技巧總結》及《Android控件用法總結

希望本文所述對大家Android程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 河西区| 广州市| 斗六市| 元阳县| 资中县| 平乡县| 自贡市| 沿河| 昆山市| 祁东县| 南阳市| 新闻| 博罗县| 许昌县| 澄城县| 清丰县| 马龙县| 弥勒县| 惠东县| 沁阳市| 云阳县| 崇左市| 镇平县| 白河县| 梧州市| 云和县| 大城县| 和硕县| 霍山县| 皋兰县| 青河县| 上林县| 会理县| 客服| 通道| 甘孜县| 修武县| 交口县| 新龙县| 海安县| 常熟市|