你的位置:首页 > 操作系统

[操作系统]andriod RadioButton


<??>  <LinearLayout android:orientation="vertical" android:layout_height="fill_parent" android:layout_width="fill_parent" ="http://schemas.android.com/apk/res/android">  <TextView android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="多选控件:" android:id="@+id/label"/>  <RadioGroup android:orientation="horizontal" android:layout_height="fill_parent" android:layout_width="fill_parent" android:id="@+id/radionGroup">  <RadioButton android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="女" android:id="@+id/radioFemale"/>  <RadioButton android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="男" android:id="@+id/radioMale" android:checked="true"/>  <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="确定" android:id="@+id/ok"/></RadioGroup></LinearLayout>

package com.example.yanlei.mytk;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.view.View;import android.widget.Button;import android.widget.RadioButton;public class MainActivity extends AppCompatActivity {  private RadioButton radioFemale;  private RadioButton radioMale;  private Button ok;  @Override  protected void onCreate(Bundle savedInstanceState) {    // TODO Auto-generated method stub    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_main);    radioFemale=(RadioButton)findViewById(R.id.radioFemale);    radioMale=(RadioButton)findViewById(R.id.radioMale);    ok=(Button)findViewById(R.id.ok);    ok.setOnClickListener(new View.OnClickListener() {      @Override      public void onClick(View v) {        String result = "你选择的是:";        if (radioFemale.isChecked()) {          setTitle(result + "女");        } else {          setTitle(result + "男");        }      }    });  }}