Spinner in Android

In this tutorial, we will learn about Spinner in Android. If you ever worked in Java AWT or Swing then you might be familiar with ComboBox. Spinner is same as those ComboBoxes. Spinner allows a user to choose from multiple choices and the user can select only one option at a single time. For example, you are making an app for an educational institute and you have an activity in your application where a user can apply for a course. In this kind of situation, you can use Spinner which would allow the user to select one course from many. In this tutorial firstly we will learn about Array Adapters then we will move to Spinners.

Array Adapter : –

An ArrayAdapter is a class in Android which work like a bridge between UI components and source of data. The data can be in any form like in the form of a list, in the form of Cursor object or in the form of Array. Array adapter mainly works with simple text data. In this tutorial, we will use an Array as our data source. To understand more about ArrayAdapter we will follow an illustration.

Spinner in Android

In this illustration, you can see Adapter is working in the centre of our Data source and Adapter View. The adapter will take data from the data source and will send it to Adapter View and after merging data and adapter view. We will set this adapter to our spinner. It might be confusing at present for many students but after seeing examples you will find it easy. So to start with spinner firstly we will add spinner in our main XML layout file.

Spread the love