Skip to content

Instantly share code, notes, and snippets.

@sandeepyohans
Created September 10, 2019 11:12
Show Gist options
  • Save sandeepyohans/4e13aa76d9c64c67a0ea730f2acacc78 to your computer and use it in GitHub Desktop.
Save sandeepyohans/4e13aa76d9c64c67a0ea730f2acacc78 to your computer and use it in GitHub Desktop.
Create Spinner and populate data in it - Android
// Create a collection and initialize it with data
ArrayList<String> list = new ArrayList<>();
for (int i=0; i<10; i++) {
list.add("Item "+i);
}
// Create an adapter for Spinner
ArrayAdapter<String> spinAdapter = new ArrayAdapter<>(context,android.R.layout.simple_list_item_1, list);
// Set the adapter to Spinner
spinner.setAdapter(spinAdapter);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment