Options on spinner based on which button clicked in Android
I have this layout with buttons A & B and a spinner under them. The A & B buttons work like radio buttons. I want to make it, when the user clicks button A, the spinner shows options for example 1,2,3,4 but when the user clicks the button B, the spinner will only give 1 & 2 as the options.
Code:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.create_game);
Spinner spinner_player = (Spinner) findViewById(R.id.spinner_player);
ArrayAdapter<CharSequence> a = ArrayAdapter.createFromResource(
this, R.array.player_array, android.R.layout.simple_spinner_item);
a.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner_player.setAdapter(a);
spinner_player.se开发者_如何学PythontSelection(1);
((RadioButton)findViewById(R.id.radio_sudoku)).setChecked(true);
}
You set spinner's contents in code, so nothing prevents you from changing them in response to button click. Or just create two spinners and make one hidden, and on button click change visibility of spinners.
精彩评论