Fill / Populate android spinner from array list

There are specific scenario when we need to fill the android spinner from array list to dynamic fill the spinner data.

//sppinnder data create arrary listArrayList arrayList = new ArrayList<>();
arrayList.add("yoo");
arrayList.add("bye bye");
arrayList.add("bye bye");
arrayList.add("bye bye");
arrayList.add("bye bye");
arrayList.add("bye bye");
arrayList.add("bye bye");
arrayList.add("bye bye");
arrayList.add("bye bye");
arrayList.add("bye bye");
arrayList.add("bye bye");
arrayList.add("bye bye");
arrayList.add("bye bye");
arrayList.add("bye bye");
arrayList.add("bye bye");
arrayList.add("bye bye");
arrayList.add("bye bye");



spinner = findViewById(R.id.spinner);
//create array adapter and provide arrary list to itArrayAdapter arrayAdapter = new ArrayAdapter(this,android.R.layout.simple_spinner_item,arrayList);
arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(arrayAdapter);


get the source from :
https://github.com/sapandang/AndroidFeatures/tree/master/app/src/main/java/skd/app/androidfeatures/dropdowns


Comments