在 xml中写入下面的代码
<RadioGroup
android:layout_toRightOf="@+id/txtpref"
android:layout_marginLeft="10sp"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:textColor="#000000"
android:text="Male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radiobutton1"/>
<RadioButton
android:textColor="#000000"
android:text="Female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radiobutton2"/>
</RadioGroup>
In Your Java file
RadioButton radiobutton1,radiobutton2;
String [] name_array,type_array;
String [] temparray;
temparray = (name_array or type_array)
ArrayAdapter arrayAdapter =new ArrayAdapter<String>(Activity_Name.this,android.R.layout.simple_spinner_item, temparray);
arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
radiobutton1 = (RadioButton) findViewById(R.id.radiobutton1);
radiobutton2 = (RadioButton) findViewById(R.id.radiobutton2);
radiobutton1.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
temparray = name_array;
your_adapter.notifyDataSetChanged();
}
}
});
radiobutton2.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
temparray = type_array;
your_adapter.notifyDataSetChanged();
}
}
});