How to create Custom Spinner?

by / Monday, 05 August 2013 / Published in Android

Spinners provide a quick way to select one value from a set. In the default state, a spinner shows its currently selected value. Touching the spinner displays a dropdown menu with all other available values, from which the user can select a new one.Creating custom spinner user can create customized Spinner with the combination of text,imageview etc.


CustomSpinnerFlagAdapter csfAdapter;

String flagimg[];

String flagname[];

flagimg=getResources().getStringArray(R.array.flag);//create an string array by fetching value from xml
flagname=getResources().getStringArray(R.array.value);//create string array  from string.xml

csfAdapter=new CustomSpinnerFlagAdapter(MainActivity.this, R.layout.custom, flagname,flagimg); //create an adapter class containing the flag image and flag name

flagSpinner=(Spinner)findViewById(; //create an instance of spinner

flagSpinner.setAdapter(csfAdapter); // set adapter to the spinner for showing the values