Open In App
Related Articles

How to Implement Custom Searchable Spinner in Android?

Improve Article
Save Article
Like Article

Android Spinner is a view similar to the dropdown list which is used to select one option from the list of options. It provides an easy way to select one item from the list of items and it shows a dropdown list of all values when we click on it. The default value of the android spinner will be the currently selected value and by using an Adapter we can easily bind the items to the spinner objects. In this article, we are going to implement a custom searchable spinner in the Android Studio so that we can provide a better user experience to the user and make it convenient for them to search and select an item in a list of items. Advantages of a searchable spinner:

  • It provides an edge over the normal listview as here the user can directly search an item rather than scrolling the whole list.
  • Searching makes users’ work easier so, many items can be inserted into a single list.

What we are going to build in this article?

Here we are going to take an array list and then insert different items into that list and then using a dialog and adapter we are going to make that list searchable and selectable. Below is a sample video of a custom searchable spinner that we are going to build in this article. Note that we are going to implement this project using the Java language. 

Step by Step Implementation

Step 1: Create a new project

  • Open a new project.
  • We will be working on Empty Activity with language as Java. Leave all other options unchanged.
  • You can change the name of the project at your convenience.
  • There will be two default files named activity_main.xml and

If you don’t know how to create a new project in Android Studio then you can refer to How to Create/Start a New Project in Android Studio?  

Step 2: Add a new vector asset in drawable

Navigate to drawable > right-click > new > vector asset and then select the following drop-down asset from clip art.

Step 3: Working with the activity_main.xml file

Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file. 


<?xml version="1.0" encoding="utf-8"?>
<!-- Relative layout as parent layout -->
  <!-- text view to show the selected item-->
        android:hint="Select course"


Step 4: Creating a new resource file


Navigate to the app > res > layout > right click > New  > Layout Resource File and then name it as dialog_searchable_spinner.



Use the below code in the dialog_searchable_spinner.xml file



<?xml version="1.0" encoding="utf-8"?>
<!-- Linear layout as parent layout-->
    <!-- Text view to show the text Select course-->
        android:text="Select Course"
    <!-- Edit text to allow user to type name
           of item he/she wants to search-->
      <!-- List view to insert list of items-->


Step 5: Working with the file


Go to the file and refer to the following code. Below is the code for the file. Comments are added inside the code to understand the code in more detail.



package com.example.custom_searchable_spinner;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
    // Initialize variable
    TextView textview;
    ArrayList<String> arrayList;
    Dialog dialog;
    protected void onCreate(Bundle savedInstanceState) {
        // assign variable
        // initialize array list
        arrayList=new ArrayList<>();
        // set value in array list
        arrayList.add("DSA Self Paced");
        arrayList.add("Complete Interview Prep");
        arrayList.add("Amazon SDE Test Series");
        arrayList.add("Compiler Design");
        arrayList.add("Git & Github");
        arrayList.add("Python foundation");
        arrayList.add("Operating systems");
        arrayList.add("Theory of Computation");
        textview.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                // Initialize dialog
                dialog=new Dialog(MainActivity.this);
                // set custom dialog
                // set custom height and width
                // set transparent background
                dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                // show dialog
                // Initialize and assign variable
                EditText editText=dialog.findViewById(;
                ListView listView=dialog.findViewById(;
                // Initialize array adapter
                ArrayAdapter<String> adapter=new ArrayAdapter<>(MainActivity.this, android.R.layout.simple_list_item_1,arrayList);
                // set adapter
                editText.addTextChangedListener(new TextWatcher() {
                    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                    public void onTextChanged(CharSequence s, int start, int before, int count) {
                    public void afterTextChanged(Editable s) {
                listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                        // when item selected from list
                        // set selected item on textView
                        // Dismiss dialog


We have successfully made the Custom Searchable Spinner for our application. The final output is shown below.




Last Updated : 28 Feb, 2022
Like Article
Save Article
Similar Reads