編輯:關於Android編程
在還沒給大家介紹單選按鈕(RadioGroup)的使用,先給大家展示下效果圖吧:

xml文件
<LinearLayout xmlns:android="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=".MainActivity" android:orientation="vertical"> <TextView android:id="@+id/txt" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="您的性別為"/> <RadioGroup android:id="@+id/sex" android:layout_width="fill_parent" android:layout_height="wrap_content"> <RadioButton android:id="@+id/male" android:text="男"/> <RadioButton android:id="@+id/female" android:text="女"/> </RadioGroup> </LinearLayout>
java文件
public class
MainActivity extends Activity {
private TextView txt=null;
private RadioGroup sex=null;
private RadioButton male=null;
private RadioButton female=null;
@Override
protected void
onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.txt=(TextView)
super.findViewById(R.id.txt);
this.sex=(RadioGroup)
super.findViewById(R.id.sex);
this.male=(RadioButton)
super.findViewById(R.id.male);
this.female=(RadioButton)
super.findViewById(R.id.female);
this.sex.setOnCheckedChangeListener(new
OnCheckedChangeListenerImp());
} private class
OnCheckedChangeListenerImp implements
OnCheckedChangeListener{
public void
onCheckedChanged(RadioGroup group, int checkedId)
{ String temp=null;
if(MainActivity.this.male.getId()==checkedId){
temp="男";
} else if(MainActivity.this.female.getId()==checkedId){
temp="女";
} MainActivity.this.txt.setText("您的性別是"+temp);
} }
以上所述是小編給大家介紹的Android程序開發中單選按鈕(RadioGroup)的使用詳解,希望對大家有所幫助!
Android開發之Activity的生命周期
可能很多人會感覺Activity很簡單,但是經歷了半年的android開發,我發現我對Activity的的理解還是比較淺顯的,其實Activity並沒有我們想
Bluestacks安裝本地APK應用圖解教程
Bluestacks安卓模擬器要怎麼安裝自己下載到電腦上的本地APK文件呢?如果你沒有安裝360助手之類的軟件,Bluestacks默認會關聯電腦上的APK
AngularJS進階(二十八)解決AngualrJS頁面刷新導致異常顯示問題
解決AngualrJS頁面刷新導致異常顯示問題 緒 俗話說,細節決定成敗,編程亦是如此。編程過程中我們可能會不自覺的忽視一些細節問題,殊不知,這些細節
谷歌市場Day1
准備階段 將WebInfos文件夾放在手機存儲卡的根目錄下,用Eclipse導入項目WebSerser,運行到手機中。 將WebInfos文件夾放在手機存