Hello everyone………

You all knew that a spinner or combobox is an inbuilt widget in android. And Like any other widgets spinners are also customizable.

Custom Spinner in Android

Here is a simple example to customize a spinner. First we will look at the java code.
The getView method is called for each row in the spinner. So with the help of an Layout Inflater you can inflate any layout for each row.
At extreme you can have each layout for each row.

Check these older posts about spinner.

1. How to get a selected Item from a spinner in ANDROID?

2. How to set an item selected in Spinner in ANDROID?

3. How to create a custom ListView in android?

Check out these of ListViews

1. Simplest Lazy Loading ListView Example in Android with data populated from a MySQL database using php.

2. How to add checkboxes and radio buttons to ListView in android? OR How to set single choice items in a ListView in android?


Now we will look at the source code

MyCustom Object for the Spinner..

package com.coderzheaven.customspinner;

public class ListItem {
    String name, place;
    int logo;

    public void setData(String name, String place, int logo) {
        this.name = name;
        this.place = place;
        this.logo = logo;

CustomAdapter for the Spinner.

package com.coderzheaven.customspinner;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;

public class MyAdapter extends ArrayAdapter<ListItem> {

    LayoutInflater inflater;
    ArrayList<ListItem> objects;
    ViewHolder holder = null;

    public MyAdapter(Context context, int textViewResourceId, ArrayList<ListItem> objects) {
        super(context, textViewResourceId, objects);
        inflater = ((Activity) context).getLayoutInflater();
        this.objects = objects;

    public View getDropDownView(int position, View convertView, ViewGroup parent) {
        return getCustomView(position, convertView, parent);

    public View getView(int position, View convertView, ViewGroup parent) {
        return getCustomView(position, convertView, parent);

    public View getCustomView(int position, View convertView, ViewGroup parent) {

        ListItem listItem = objects.get(position);
        View row = convertView;

        if (null == row) {
            holder = new ViewHolder();
            row = inflater.inflate(R.layout.row, parent, false);
            holder.name = (TextView) row.findViewById(R.id.name);
            holder.place = (TextView) row.findViewById(R.id.place);
            holder.imgThumb = (ImageView) row.findViewById(R.id.imgThumb);
        } else {
            holder = (ViewHolder) row.getTag();


        return row;

    static class ViewHolder {
        TextView name, place;
        ImageView imgThumb;

Layout for the Spinner Row


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

        android:background="@drawable/google" />

        android:textStyle="bold" />

        android:text="Heaven of all working codes"
        android:textColor="@android:color/darker_gray" />


package com.coderzheaven.customspinner;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.Spinner;
import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    protected void onCreate(Bundle savedInstanceState) {

        Spinner mySpinner = (Spinner) findViewById(R.id.spinner);
        mySpinner.setAdapter(new MyAdapter(this, R.layout.row, getAllList()));

    public ArrayList<ListItem> getAllList() {

        ArrayList<ListItem> allList = new ArrayList<ListItem>();

        ListItem item = new ListItem();
        item.setData("Google", "USA", R.drawable.google);

        item = new ListItem();
        item.setData("Apple", "USA", R.drawable.apple);

        item = new ListItem();
        item.setData("Samsung", "Korea", R.drawable.samsung);

        item = new ListItem();
        item.setData("Sony", "Japan", R.drawable.sony);

        item = new ListItem();
        item.setData("HTC", "Taiwan", R.drawable.htc);

        for (int i = 0; i < 10000; i++) {
            item = new ListItem();
            item.setData("Google " + i, "USA " + i, R.drawable.google);

        return allList;

You can download the complete Android Studio Source Code from here.



  1. kamal August 1, 2011 at 4:31 pm

    good tutorial, I would like to ask one question that, how to display the spinner list View just below the spinner and making it’s width smaller. thank you.

    • James August 1, 2011 at 9:02 pm

      Make the first row transparent.

  2. Ali September 8, 2011 at 7:09 pm

    Good tutorial.
    Keep it up!

  3. David October 21, 2011 at 1:59 pm

    Hello, I have been trying to do something like this for some time now. All teh samples I look at seem to be missing something (or don’t explain it well). Your example has been the most complete, but I am still having problems.

    lines 30 and 52 have .row highlighted.
    my suggested corrections are to create field row in type layout, or create constant row in type layout.

    Any ideas? No other errors listed elsewhere.

    I tried renaming spinner.row.xml to spinnerrow.xml and changing .row to spinnerrow on lines 30 and 52, but that didnt work.

    I tried

    • David October 21, 2011 at 2:15 pm

      Doh! I got it. I renamed the xml file to row.xml.


      Thanks for the example!

  4. mart November 30, 2011 at 12:23 am

    This is the tutorial I wanted to see! many thanks to you!

    Now I have a question.
    When the spinner is not expanded (like the first of the two pictures you show (http://coderzheaven.com/wp-content/uploads/2011/07/Custom-Spinner-Demo1.png)), I do not want it to display the choice you made (in this picture it is the first with “Coderzheaven, heaven of all working codes”)
    How can I realize this?


    • James November 30, 2011 at 9:29 pm

      Hey mart :- If you dont want to show the first option when the spinner is not expanded then make your array of strings with a blank field in the first index. Is that you want or anything else. please explain.
      Or call this
      mySpinner.setAdapter(new MyAdapter(CustomSpinnerDemo.this, R.layout.row, strings));
      when your spinner expands to reset it’s data with your choice in the first index of the string array when it expands.

  5. fadim June 20, 2012 at 10:27 am

    Thank you so much its very useful 😀

  6. Joe August 16, 2012 at 3:57 am

    Thank you for the excellent tutorial. Its precise and to the point.

  7. Arefin August 22, 2012 at 9:11 am

    Hi, I was wondering if you could explain this span thing.
    package pack.coderzheaven;

    I am new to this kind of thing. Since I am not aware of span, I also could not complete the tutorial because of errors. Please do mention what alternatives can be used instead.

    • James August 23, 2012 at 10:34 am

      Sorry, that’s the problem with my syntax highlighter. please remove those HTML span tags and proceed.

  8. Rash October 18, 2012 at 2:46 pm

    How can i use custom font(such as Bangla,Hindi….) in spinner text …?

  9. vaishali November 17, 2012 at 1:45 pm

    how to do the same thing using sqlite. i mean if i have to fetch these values from database, in that case how it will be done?

  10. luke November 28, 2012 at 11:06 pm

    what if i want the items on spinner to take me to another activity, please write the code, ive tried everything

    • James November 29, 2012 at 3:26 am

      just write an onItemSelected Listener for the spinner and inside that call the startActivity.

  11. Pingback: Only images in a spinner : Android Community - For Application Development

  12. Pingback: ImageView in Spinner items : Android Community - For Application Development

  13. ali July 31, 2013 at 12:24 pm

    great job
    its woriking perfectly. but how can i get the String[] strings from the string,.xml in value folder for translation?
    i tried to do it with getResource.getString(R.array.something)
    but the app is crashing.
    what to do please help.
    thanks in advance

  14. Leonardo Martinez July 15, 2014 at 5:12 am

    Saves my day , thanks it helps a lot and very easy to understand.

  15. bedirhan July 22, 2014 at 11:53 am

    hey thats a very good tutorial.ı am new on android and ı need the add image to spinner but ı cant do this.ı already have spinner and add some items in it.would you make a tutorial video about that cause ı barely understand.

  16. Rachit Kalra September 7, 2014 at 8:42 pm

    Hey thanks for the help , gave me a quick walk through and general how adapter api’s wrk (y)

  17. Samir Samedov August 4, 2017 at 2:06 pm

    Thank you worked pretty well. Just added setters and getters to ListItem fields and called them getName() getLogo()


Leave a Reply

Your email address will not be published. Required fields are marked *




Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.