‫Welcome back.
‫In this video, we'll learn about spinners in Android studio.
‫There are a lot of information in this video.
‫So I want from you to focus with me.
‫Spinner is a UI widget that displays a drop down list of items from which users can select a single
‫option.
‫It's similar to radial group.
‫A spinner is often used when you want users to choose from a set of predefined options.
‫First of all, let's define our spinner in the layout XML.
‫I'll start with a spinner wrap content wrap content and you can see this is the dropdown menu.
‫Let's move to the main activity to reference the spinner and set up an array adapter to populate the
‫dropdown list with data.
‫The second step is to create the array adapter.
‫Array Adapter of type string.
‫I'll name it as adapter equal to new array adapter.
‫An array adapter is a class that acts as a bridge between an array or a list of data and the list of
‫new grid view spinner or other similar UI widgets.
‫It's commonly used to populate these widgets with data and display them to the user.
‫An array adapter takes care of converting each item in the data source into a corresponding view that
‫can be displayed within the UI.
‫To create an array adapter, you typically use one of its constructors.
‫If I click Ctrl and left mouse, you can see the different types of constructors.
‫I'll use the constructor that takes a context, a layout resource for the individual item and the data
‫source, which is usually an array or a list.
‫I'll use this as a context, and the context is a fundamental class that represents the current state
‫and environment in which an application is running.
‫It provides access to various resources, system services and information about the application's execution
‫context.
‫Context is an essential concept in Android development, and it's used extensively to interact with
‫Android system and perform various tasks.
‫Later on we'll talk about array adapters and different types of adapters and we'll talk about context
‫in details.
‫The second parameter is the data source or the array of data.
‫I'll create an array here.
‫It's of type string array.
‫I'll name it as courses equal to.
‫And these strings are the items of this courses array.
‫C plus plus Java, Kotlin and Python.
‫I need to pass the data source here, which is courses.
‫The third parameter is the layout that it is used for the selected item.
‫I'll use a predefined layout which is from Android r dot layout dot simple underscore spinner dropdown
‫or I can use and we have an error here.
‫I need to permute arguments.
‫I switched the spinner item with the courses.
‫Okay.
‫So courses is the third or the array list is the third parameter that I need to pass to the adapter.
‫So this is the adapter.
‫It's acting as a bridge between the data source and the view.
‫It will supply the view with the data from the data source.
‫The last step is to apply the adapter to the spinner.
‫I'll use Spinner dot set adapter and I'll specify the adapter instance that I created before.
‫Run the application and congratulations.
‫This is our spinner.
‫You can see the items Java, Python.
‫Kotlin.