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

首頁 > 系統 > Android > 正文

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

2019-10-22 18:31:27
字體:
來源:轉載
供稿:網友

本文實例講述了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開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 霍山县| 台江县| 呼伦贝尔市| 商河县| 安新县| 犍为县| 平湖市| 普定县| 区。| 岚皋县| 丁青县| 榆社县| 防城港市| 水城县| 华坪县| 瑞昌市| 东城区| 深水埗区| 宁波市| 永胜县| 巴里| 北流市| 郸城县| 咸丰县| 白城市| 黄石市| 绵竹市| 娄烦县| 吴桥县| 洛阳市| 泌阳县| 上杭县| 胶南市| 南京市| 台湾省| 光山县| 舒兰市| 沅陵县| 吉木萨尔县| 长兴县| 盘山县|