Answer the question
In order to leave comments, you need to log in
The list is not displayed in the Android Studio spinner, how to fix it?
Hello, I searched for my mistake, found different solutions, but I still can't fix it. Perhaps I have something else. In general, I throw a request to the server, it returns a list of cities to me. After reading the json, I write the names of the cities in the ArrayList, if you just display the list everything is fine. But only the list is displayed in the spinner, and when you click on the desired city, the list remains empty...
ArrayList<String> cityList = new ArrayList<String>();
...
final Spinner spinner_city = (Spinner) findViewById(R.id.city_spinner);
ArrayAdapter<String> adapter_city = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, cityList);
adapter_city.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner_city.setAdapter(adapter_city);
spinner_city.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent,
View itemSelected, int selectedItemPosition, long selectedId) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString("City", spinner_city.getSelectedItem().toString()).apply();
}
public void onNothingSelected(AdapterView<?> parent) {
}
});
Answer the question
In order to leave comments, you need to log in
Sorry for the stupid question, I solved everything myself! The problem was that I wrote this in the request
...
@Override
public void onResponse(Response<ListSchoolCityModel> response, Retrofit retrofit) {
if (response.isSuccess()) {
//Здесь писал заполнение
}
} else {
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question