Course Content

If you are facing any issue in playing video please use Firefox browser.

Course Content


What is Spinner in Android ?

Now we will see how we can design Spinner inside Android, so for this we are creating an application named 'MySpinner'.

Stepwise :

  1. First we will see its manifest file which is generated by default.
  2. After that we will design its layout, for that we will open xml inside the 'layout' folder which is inside the 'res' folder. Here we have taken a relative layout, we have set the basic properties of the relative layout, now we need to design a spinner here, so for that first we will use the spinner tag, and set some of its basic properties.
  3. Now after this we will design a text view here, we will use the text view to display the items of the spinner. So, we have used a spinner and a text view inside our relative layout.
  4. Now we will see our main activity inside our 'java' folder, which is generated by default.
  5. Now we will design the spinner's code, first of all we will create an array 'state' within which we have specified the names of different versions of Android.
  6. Now we will generate the spinner and text view instants here.
  7. Now we will also identify the spinner and the text view we have taken.
  8. Right here, we have to use an ArrayAdapter, with its we can display the items of the array in a spinner. So we have created an ArrayAdapter 'adapter_state', inside which we are passing 'this' in the argument. And then we specified 'simple_spinner_item'
  9. After that we will pass the array we have created.
  10. Now after this we have to set the dropdown list, for this we will use the instance of the adapter that we have created, and then we will use 'setDropDownViewResource', and after that we have selected 'simple_spinner_dropdown_item'.
  11. Now we have to set the adapter, for this we will use instance, and after that we will use 'setOnItemSelectedListener'.
  12. Now we have used 'OnItemSelected' with the adapter view. Now we will first specify setSelection in which we will specify the argument's position. String selState = (String)spinnerOsversions.getSelectedItemId();
  13. So like this with the help of an ArrayAdapter we have created a Spinner, which means that content of spinner are printed through the contents of ArrayAdapter.
  14. Now we'll execute it and see how our code runs. As soon as we click on 'run app' , our app runs accurately.


Recommended Courses

Share With Friend

Have a friend to whom you would want to share this course?

Download The Apps

App Preview Image
App QR Code Image
Code Scan or Download the app
Google Play Store
297K+ Downloads
App Download Section Circle 1
4.5 Rating
App Download Section Circle 2
10K+ Reviews
App Download Section Circle 3
  • Learn anywhere on the go
  • Get regular updates about your enrolled or new courses
  • Share content with your friends
  • Evaluate your progress through practice tests
  • No internet connection needed
  • Enroll for the webinar and join at the time of the webinar from anywhere