1.) Initialize first
String[] gender;
2.) Now Create Method
setValueInSpinner(gender_spinner,gender);
genderSpinnerListener();3.) Copy The Below Codeprivate void setValueInSpinner(Spinner gender_spinner, String[] gender) {
ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, gender);
adapter.setDropDownViewResource(android.R.layout.simple_selectable_list_item);
gender_spinner.setAdapter(adapter);
}4.) Copy The Below Codeprivate void genderSpinnerListener() {
gender_spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Object item = parent.getItemAtPosition(position);
if (item.equals("Select Gender")){
} else if (item.equals("Male")) {
}
else if (item.equals("Female")) {
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
0 Comments