D
D
Drunk_bear642019-06-13 20:09:46
Java
Drunk_bear64, 2019-06-13 20:09:46

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) {
            }
        });

5d02833bb7f11622202503.png
5d028350e347b266521211.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Drunk_bear64, 2019-06-13
@Drunk_bear64

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 {
                }
            }

After filling the spinnera output in a separate method and call already in the same place in the request, then everything works fine.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question