Answer the question
In order to leave comments, you need to log in
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));
}
// адаптер
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) {
}
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question