F
F
Fotonick2015-07-11 14:10:46
Android
Fotonick, 2015-07-11 14:10:46

Why does the spinner work differently on emulators of different versions?

In my application, I receive a response from the server - a list of car brands and throw this list into a drop-down list (spinner). In the api22 emulator (android 5.1.1), the order of the marks in the spinner is the same as in the response from the server, but if you run it in the api19 emulator (android 4.4.2) or really on my Asus Zenfone 5 (also 4.4.2), then the order stamps in the spinner becomes somehow random. What's the matter? What to fix?
this is how I throw the server response into an ArrayList

String responseString =responseOutput.toString();

                JSONObject jsonResponse = new JSONObject(responseString);

                for(Iterator<String> iter = jsonResponse.keys();iter.hasNext();) {
                    String key = iter.next();
                    marka.add(jsonResponse.getString(key));
                }

this is how I make a spinner adapter
// адаптер
        ArrayAdapter adapterMarka = new ArrayAdapter(this, android.R.layout.simple_spinner_item, marka);
        adapterMarka.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        Spinner markaSp = (Spinner) findViewById(R.id.marka);

        markaSp.setAdapter(adapterMarka);

        // устанавливаем обработчик нажатия
        markaSp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view,
                                       int position, long id) {
                // показываем позиция нажатого элемента
                makeText(getBaseContext(), "Position = " + position, LENGTH_SHORT).show();
            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
            }
        });

a3f05b5410e84adbbf8284fd66534f00.png133a96a73c31496d9aae98884be7e183.pngcd4fa6803d16462e83ae639dbfd4630c.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question