0
我有一個微調器可以顯示兩個選項,但是當我接受女性選項時,它仍然將男性的答案作爲答案,有什麼建議嗎?微調器數據接受是多功能的
List<String> SpinnerArray = new ArrayList<String>();
SpinnerArray.add("Male");
SpinnerArray.add("Female");
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, SpinnerArray);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Spinner Items = (Spinner) findViewById(R.id.genderSpinner);
Items.setAdapter(adapter);
// Importing all assets like buttons, text fields
inputFullName = (EditText) findViewById(R.id.registerName);
String selected = Items.getSelectedItem().toString();
if (selected.equals("Male")) {
inputGen = "Male";
}
if (selected.equals("Female")){
inputGen = "Female";
}
你有沒有考慮過使用'getSelectedItemPosition()'?然後'if(selected == 0){.....}'和'else if(selected == 1){.....}' – EdmDroid