android RadioGroup的使用方法
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:id="@+id/radiobutton_textview"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:textSize="18dip"
android:textStyle="bold"
android:background="@android:drawable/title_bar"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
/>
<RadioGroup
android:id="@+id/group"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:textSize="20dip"
android:paddingLeft="30dip"
android:text="Android新手"
android:button="@null"
android:drawableRight="@android:drawable/btn_radio"/>
<View
android:layout_width="fill_parent"
android:layout_height="1px"
android:background="?android:attr/listDivider"
/>
<RadioButton
android:id="@+id/button2"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:textSize="20dip"
android:paddingLeft="30dip"
android:text="Android高手"
android:button="@null"
android:drawableRight="@android:drawable/btn_radio"/>
</RadioGroup>
</LinearLayout>
Xml代碼
package endual.radio;
import android.app.Activity;
import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;
public class MainActivity extends Activity {
private TextView textView;
private RadioGroup group;
private RadioButton rb1 ;
private RadioButton rb2 ;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textView = (TextView) findViewById(R.id.radiobutton_textview);
group = (RadioGroup) findViewById(R.id.group);
this.rb1 = (RadioButton) this.findViewById(R.id.button1) ;
this.rb2 = (RadioButton) this.findViewById(R.id.button2) ;
// 單選按鈕組監(jiān)聽(tīng)事件
group.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// 根據(jù)ID判斷選擇的按鈕
if (checkedId == R.id.button1) {
textView.setText("Android新手");
rb1.setText("我是1") ;
String msg = rb1.getText().toString() ; //獲取單獨(dú)的radioButton的按鈕
rb2.setText(msg) ;
//System.out.println();
} else {
textView.setText("Android高手");
rb2.setText("我是2") ;
}
}
});
}
}
RadioGroup注冊(cè)監(jiān)聽(tīng)事件OnCheckedChangeListener(),在onCheckedChanged實(shí)現(xiàn)業(yè)務(wù)邏輯。
- Android控件系列之RadioButton與RadioGroup使用方法
- android自定義RadioGroup可以添加多種布局的實(shí)現(xiàn)方法
- Android程序開(kāi)發(fā)中單選按鈕(RadioGroup)的使用詳解
- Android開(kāi)發(fā)之RadioGroup的簡(jiǎn)單使用與監(jiān)聽(tīng)示例
- Android RadioGroup和RadioButton控件簡(jiǎn)單用法示例
- Android RadioGroup 設(shè)置某一個(gè)選中或者不可選中的方法
- Android使用RadioGroup實(shí)現(xiàn)底部導(dǎo)航欄
- Android實(shí)現(xiàn)界面內(nèi)嵌多種卡片視圖(ViewPager、RadioGroup)
- Android 自定義View實(shí)現(xiàn)任意布局的RadioGroup效果
- Android基礎(chǔ)控件RadioGroup使用方法詳解
相關(guān)文章
Flutter?SystemChrome控制應(yīng)用程序的系統(tǒng)級(jí)別行為
這篇文章主要為大家介紹了Flutter?SystemChrome用來(lái)控制應(yīng)用程序的系統(tǒng)級(jí)別行為步驟詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-05-05
Android編程實(shí)現(xiàn)Dialog窗體監(jiān)聽(tīng)的方法
這篇文章主要介紹了Android編程實(shí)現(xiàn)Dialog窗體監(jiān)聽(tīng)的方法,結(jié)合實(shí)例形式分析了Android針對(duì)Dialog對(duì)話框窗體事件監(jiān)聽(tīng)與響應(yīng)相關(guān)操作技巧,需要的朋友可以參考下2017-03-03
Android獲取手機(jī)型號(hào)/系統(tǒng)版本號(hào)/App版本號(hào)等信息實(shí)例講解
本示例獲得手機(jī)型號(hào),系統(tǒng)版本,App版本號(hào)等信息,具體實(shí)現(xiàn)如下,感興趣的朋友可以參考下哈2013-06-06
Android Studio中引入Lambda表達(dá)式的方法
這篇文章主要給大家介紹了在Android Studio中引入Lambda表達(dá)式的方法,文中通過(guò)圖文介紹的非常詳細(xì),對(duì)大家具有一定的參考價(jià)值,需要的朋友們下面來(lái)一起看看吧。2017-03-03
Android通話默認(rèn)打開(kāi)揚(yáng)聲器的方法
這篇文章主要介紹了Android通話默認(rèn)打開(kāi)揚(yáng)聲器的方法.小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-08-08
Android LinearLayout實(shí)現(xiàn)自動(dòng)換行
這篇文章主要為大家詳細(xì)介紹了Android LinearLayout實(shí)現(xiàn)自動(dòng)換行,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-08-08
Android Studio Gradle插件版本與Gradle版本之間的對(duì)應(yīng)關(guān)系
今天小編就為大家分享一篇關(guān)于Android Studio Gradle插件版本與Gradle版本之間的對(duì)應(yīng)關(guān)系,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2018-12-12
android實(shí)現(xiàn)簡(jiǎn)單儀表盤(pán)效果
這篇文章主要為大家詳細(xì)介紹了android實(shí)現(xiàn)簡(jiǎn)單儀表盤(pán)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-05-05

