Android Drop Down List Tutorial
- Published on Aug 14, 2016
- In this tutorial you will learn what is android spinner (android drop down list), how to create spinner, android spinner adapter and how to use it inside your app.
- First open up activity_main.xml file and then replace the hello world textview with a spinner, then we will position the spinner to the top-center of the screen like this:
- Now open up MainActivity.java class and declare the spinner like this:
Spinner mySpinner = (Spinner) findViewById(R.id.spinner1);
- Next is we need some data to populate the spinner adapter, we can do that by adding an array of items inside the strings.xml file which you can find it in the (Res) folder, then we can reference that array by it's ID and use it for the adapter.
That's it...Run the app and you will see a spinner with values being populated whenever the user taps on it
Source code is here: github.com/codingdemos/SpinnerExample