Android tutorial - spinner android - android app development - android studio - android development tutorial
Learn android - android tutorial - Spinner android - android examples - android programs
Android Spinner:
- Android Spinner is like the combox box of AWT or Swing. It can be used to display the multiple options to the user in which only one item can be selected by the user.
- Android spinner is like the drop-down menu with multiple values from which the end user can select only one value.
- Android spinner is associated with AdapterView. So, you need to use one of the adapter classes with spinner.
- Android Spinner class is the subclass of AsbSpinner class.
Drop down list is nothing but
- A drop down will generate or display a list of items once it’s clicked.
- Render a Spinner in XML, and load the selection items via XML file also.
- Render another Spinner in XML, and load the selection items via code dynamically.
- Attach a listener on Spinner, fire when user select a value in Spinner.
- Render and attach a listener on a normal button fire when user click on it, and it will display selected value of Spinner.
1. List of Items in Spinner
- Open “res/values/strings.xml” file,
- Define the list of items that will display in Spinner (dropdown list).
- File : res/values/strings.xml
2. Spinner (DropDown List)
- Open “res/layout/main.xml” file, add two spinner components and a button.
- In “spinner1”, the “android:entries” represents the selection items in spinner.
- In “spinner2”, the selection items will be defined in code later.
- File : res/layout/main.xml
3. Android Code
- File : MyAndroidAppActivity.java
- File : CustomOnItemSelectedListener.java
4. Demo - android emulator - android tutorial
- Run the application.
- Result, two spinners are displayed
- Select “France” from spinner1, item selection listener is fired :