首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

RadioGroup容易应用

2012-10-11 
RadioGroup简单应用???????xml version1.0 encodingutf-8?LinearLayout xmlns:androidhttp://s

RadioGroup简单应用

?

?

?

?

?

?

<?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:layout_width="fill_parent"    android:layout_height="wrap_content"    android:text="@string/title"    /> <RadioGroup  android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/radioGroup" > <RadioButton  android:text="@string/red" android:id="@+id/radioButton_1" android:layout_width="wrap_content" android:layout_height="wrap_content" />  <RadioButton  android:text="@string/green" android:id="@+id/radioButton_2" android:layout_width="wrap_content" android:layout_height="wrap_content" />  <RadioButton  android:text="@string/blue" android:id="@+id/radioButton_3" android:layout_width="wrap_content" android:layout_height="wrap_content" />  </RadioGroup>        <TextView    android:layout_width="fill_parent"    android:layout_height="wrap_content"    android:text=""    android:id="@+id/textTip"    />       </LinearLayout>

?

?

?

?

public class RadioButtonActivity extends Activity {    /** Called when the activity is first created. */private RadioGroup radioGroup;private RadioButton radioButton_1;private RadioButton radioButton_2;private RadioButton radioButton_3;private TextView textTip;    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);                radioGroup = (RadioGroup) findViewById(R.id.radioGroup);        radioButton_1 = (RadioButton) findViewById(R.id.radioButton_1);        radioButton_2 = (RadioButton) findViewById(R.id.radioButton_2);        radioButton_3 = (RadioButton) findViewById(R.id.radioButton_3);        textTip = (TextView) findViewById(R.id.textTip);                radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(RadioGroup group, int checkedId) {textTip.setText("选择ID:"+checkedId);}});    }}

?

?

热点排行