自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Android單選框基本應(yīng)用方式講解

移動(dòng)開(kāi)發(fā) Android
當(dāng)我們?cè)谑褂肁ndroid單選框的時(shí)候,首先應(yīng)當(dāng)先用RadioGroup來(lái)進(jìn)行分組,然后調(diào)用其中的RadioGroup的Check·()方法進(jìn)行相應(yīng)的設(shè)置。

大家可能還記得,我們51CTO曾經(jīng)為大家介紹過(guò)關(guān)于Android操作系統(tǒng)中復(fù)選框的一些應(yīng)用方式,那么今天大家將會(huì)了解到的則是關(guān)于Android單選框的一些基本概念,讓大家完全掌握這些選框的應(yīng)用,方便大家學(xué)習(xí)。#t#

●使用Android單選框的時(shí)候,要用RadioGroup來(lái)分組

●選擇RadioGroup里的單選框的時(shí)候,將調(diào)用RadioGroup的Check·()方法

●追加單選框被選擇時(shí)處理的時(shí)候,

1.調(diào)用setOnCheckedChangeListener()方法,并把RadioGroup.OnCheckedChangeListener實(shí)例作為參數(shù)傳入

2.在RadioGroup.OnCheckedChangeListener的onCheckedChanged()方法里,取得被選中Android單選框的實(shí)例

例程源碼(Java)

  1. view source print?01.RadioGroup radioGroup = (RadioGroup) 
    findViewById(id.radioGroup);   
  2. radioGroup.check(id.radioButtonGreen);  
  3. RadioButton radioButton = (RadioButton) findViewById(  
  4. radioGroup.getCheckedRadioButtonId());  
  5. Log.v("Test", String.valueOf(radioButton.getText()));  
  6. radioGroup.setOnCheckedChangeListener(  
  7. new RadioGroup.OnCheckedChangeListener() {  
  8. public void onCheckedChanged(  
  9. RadioGroup group,  
  10. int checkedId) {  
  11. RadioButton radioButton = (RadioButton) findViewById(checkedId);   
  12. Log.v("Test", String.valueOf(radioButton.getText()));  
  13. }  
  14. }); 

例程源碼(Resource)

 

  1. < RadioGroup android:id="@+id/radioGroup" 
  2. android:layout_width="wrap_content" 
  3. android:layout_height="wrap_content"> 
  4. < RadioButton android:id="@+id/radioButtonRed" 
  5. android:layout_width="wrap_content" 
  6. android:layout_height="wrap_content" 
  7. android:text="@string/Red" /> 
  8. < RadioButton android:id="@+id/radioButtonGreen" 
  9. android:layout_width="wrap_content" 
  10. android:layout_height="wrap_content" 
  11. android:text="@string/Green" /> 
  12. < RadioButton android:id="@+id/radioButtonBlue" 
  13. android:layout_width="wrap_content" 
  14. android:layout_height="wrap_content" 
  15. android:text="@string/Blue" /> 
  16. < /RadioGroup> 

Android單選框的基本應(yīng)用方式就為大家介紹到這里。

責(zé)任編輯:曹凱 來(lái)源: 博客園
相關(guān)推薦

2010-02-26 13:40:28

WCF消息頭

2010-03-04 14:57:08

Python解密VBS

2010-03-03 16:40:55

Python HTTP

2010-02-02 14:45:35

C++ typeof

2009-11-23 11:03:12

php_curl庫(kù)

2010-03-03 14:30:05

Python set類

2010-03-03 14:40:37

Python打包方法

2010-03-04 09:27:34

調(diào)用Python腳本

2010-03-03 10:03:55

Python連接Sql

2013-12-12 16:10:21

Lua腳本語(yǔ)言

2010-03-03 16:08:26

Python取得文件列

2010-03-03 15:17:46

Python調(diào)用MyS

2010-02-02 17:33:17

C++友元函數(shù)

2010-07-08 15:24:17

SNMP trap

2010-03-03 13:22:08

Python正則表達(dá)式

2010-01-25 16:52:22

Android Int

2024-01-31 11:51:50

PyQt6單選框Python

2010-02-25 10:52:29

WCF響應(yīng)服務(wù)

2010-03-01 15:40:04

WCF實(shí)例停用

2010-02-25 18:04:02

WCF IIS宿主
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)