C說話的遞歸思惟實例剖析。本站提示廣大學習愛好者:(C說話的遞歸思惟實例剖析)文章只能為提供參考,不一定能成為您想要的結果。以下是C說話的遞歸思惟實例剖析正文
本文實例講述了Android RadioGroup和RadioButton控件簡略用法。分享給年夜家供年夜家參考,詳細以下:
RadioGroup和RadioButton代表的是Android中單選按鈕的一種控件,寫個簡略的代碼熟習一下:
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 Radio extends Activity { private TextView myTextView; private RadioButton chinaBtn; private RadioButton ukBtn; private RadioButton usaBtn; private RadioGroup rg; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //經由過程ID找到TextView myTextView = (TextView) findViewById(R.id.myTextView); //經由過程ID找到RadioButton chinaBtn = (RadioButton) findViewById(R.id.china_Button); ukBtn = (RadioButton) findViewById(R.id.uk_Button); usaBtn = (RadioButton) findViewById(R.id.usa_Button); //經由過程ID找到RadioGroup rg = (RadioGroup) findViewById(R.id.rBtnGroup); //只需對RadioGroup停止監聽 rg.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { // TODO Auto-generated method stub if(R.id.china_Button == checkedId){ myTextView.setText("您選擇的國度是:" + chinaBtn.getText().toString()); } else if(R.id.uk_Button == checkedId){ myTextView.setText("您選擇的國度是:" + ukBtn.getText().toString()); } else if(R.id.usa_Button == checkedId){ myTextView.setText("您選擇的國度是:" + usaBtn.getText().toString()); } } }); } }
main.xml文件以下:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:id="@+id/myTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello" /> <RadioGroup android:id="@+id/rBtnGroup" android:layout_width="wrap_content" android:layout_height="wrap_content" > <RadioButton android:id="@+id/china_Button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="中國" /> <RadioButton android:id="@+id/uk_Button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="英國" /> <RadioButton android:id="@+id/usa_Button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="美國" /> </RadioGroup> </LinearLayout>
後果以下:
願望本文所述對年夜家Android法式設計有所贊助。