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

歡迎訪問(wèn) 生活随笔!

生活随笔

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

Android

android复选框标签,Android中的复选框的使用

發(fā)布時(shí)間:2024/10/5 Android 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android复选框标签,Android中的复选框的使用 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

復(fù)選框的使用和單選框是不同的對(duì)于單選框來(lái)說(shuō)呢,是必須要分組的每一組內(nèi)單選框只能有一個(gè)被選中,而對(duì)于復(fù)選框來(lái)說(shuō)沒(méi)有組這個(gè)概念,因?yàn)槊恳粋€(gè)都可同時(shí)被選中或者不被選中,復(fù)選框其實(shí)可以看成一個(gè)一般的按鈕,只是多了選中和沒(méi)有選中的狀態(tài)。

基于上面的不同所以單選框和復(fù)選框的事件堅(jiān)挺接口是不同的

單選框的事件監(jiān)聽(tīng)接口是?RadioGroup.OnCheckedChangeListener

復(fù)選框的事件監(jiān)聽(tīng)接口是?CompoundButton.onCheckcedChangeListener

下面是一個(gè)簡(jiǎn)單的復(fù)選框的小程序 ,實(shí)現(xiàn)的效果是在選中愛(ài)好的時(shí)候在屏幕上顯示出來(lái),取消選擇的時(shí)候從屏幕上消失 的程序:

CheckBoxMainActivity.java文件

package com.checkBox.checkbox;

import org.w3c.dom.Comment;

import android.os.Bundle;

import android.app.Activity;

import android.view.Menu;

import android.widget.CheckBox;

import android.widget.CompoundButton;

import android.widget.TextView;

public class CheckBoxMainActivity extends Activity {

private TextView text=null;

private CheckBox sw=null;

private CheckBox bs=null;

@Override

protected void onCreate(Bundle

savedInstanceState) {

super.onCreate(savedInstanceState);

super.setContentView(R.layout.activity_check_box_main);//得到控件

text=(TextView)

this.findViewById(R.id.text);

text.setText("愛(ài)好是:\t");

sw=(CheckBox)

this.findViewById(R.id.swim);

bs=(CheckBox)

this.findViewById(R.id.basketball);//**************

sw.setOnCheckedChangeListener(new

CompoundButton.OnCheckedChangeListener() {

//添加內(nèi)嵌監(jiān)聽(tīng)器

@Override

public void

onCheckedChanged(CompoundButton buttonView, boolean isChecked)

{

//

TODO Auto-generated method stub

String

favorite=text.getText().toString();

if(isChecked){

if(favorite.contains("游泳")){

}else{

text.setText(favorite+"\t游泳");

}

}else{

if(favorite.contains("游泳")){

text.setText(favorite.replace("\t游泳", ""));

}

}

}

});

bs.setOnCheckedChangeListener(new

CompoundButton.OnCheckedChangeListener() {

//給復(fù)選框添加內(nèi)部監(jiān)聽(tīng)

@Override

public void

onCheckedChanged(CompoundButton buttonView, boolean isChecked)

{

//

TODO Auto-generated method stub

String

favorite=text.getText().toString();

if(isChecked){

if(favorite.contains("籃球")){

}else{

text.setText(favorite+"\t籃球");

}

}else{

if(favorite.contains("籃球")){

text.setText(favorite.replace("\t籃球", ""));

}

}

}

});

}

@Override

public boolean onCreateOptionsMenu(Menu menu)

{

// Inflate the menu; this adds

items to the action bar if it is present.

getMenuInflater().inflate(R.menu.activity_check_box_main,

menu);

return true;

}

}

MainActivity.xml文件

http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".CheckBoxMainActivity" >

android:id="@+id/text"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerHorizontal="true"

android:layout_centerVertical="true"

android:text="@string/hello_world" />

android:id="@+id/swim"

android:text="游泳"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@+id/text"

/>

android:id="@+id/basketball"

android:text="籃球"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@+id/text"

android:layout_toRightOf="@id/swim"

/>

與50位技術(shù)專家面對(duì)面20年技術(shù)見(jiàn)證,附贈(zèng)技術(shù)全景圖

總結(jié)

以上是生活随笔為你收集整理的android复选框标签,Android中的复选框的使用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

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