Hello everyone!
Here’s another cool Android tutorial that talks about creating your own DropDown Spinner widget in Android. From the Android developers page, a Spinner is a view that displays one child at a time and lets the user pick among them.Our Default Spinner provide Drop Down above 4.0 version. In this tutorial you will create a customized Spinner like Gmail app using library project. This is also work in 4.0 below version. You can create spinner like this:
Using this Library you can set following features:
setOnItemSelectedListener
You can set custom spinner control in xml like this:
Here’s another cool Android tutorial that talks about creating your own DropDown Spinner widget in Android. From the Android developers page, a Spinner is a view that displays one child at a time and lets the user pick among them.Our Default Spinner provide Drop Down above 4.0 version. In this tutorial you will create a customized Spinner like Gmail app using library project. This is also work in 4.0 below version. You can create spinner like this:
Using this Library you can set following features:
Methods:
- setItemTextColor(int color) - Set the item text font color in drop down.
- setItemBackgroundColor(int color) - Set the item background color in drop down.
- setItemTextSize (int size) - Set the item text size
- setVisibleItemNo (int no) - Set the height of DropDown spinner equal to number of visible rows
- addItem(String item) - Add the single string item in spinner
- addItem(String item, int resId) - Add the single string item and image in spinner
- setItems(String[] arr) - Set the string array in spinner
- setItems(String[] arr, int[] ico) - Set the string array & image array in list. size of string array and image array required equal.
- getSelectedPosition() - Return the position of currently selected item within the adapter's data set.
- setSelectedPosition(int selectedPosition)- Set the currently selected item.
Listener :
setOnItemClickListenersetOnItemSelectedListener
You can set custom spinner control in xml like this:
<com.anky.dropdownspinner.DropdownSpinner
android:id="@+id/my_spinner1"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="@drawable/standard_menu_button_bg"
android:text="" />
You can set property like this:private DropdownSpinner spinner1 = (DropdownSpinner) findViewById(R.id.my_spinner1);
private String[] strings = { "Inter Milan", "AC Mila", "Manchesterb",
"Barcelona", "Valencia", "Juventus" };
spinner1.setItems(strings);
spinner1.addItem("Test1");
spinner1.addItem("Test2");
spinner1.addItem("Test3",R.drawable.ic_menu_moreoverflow_normal_holo_light);
spinner1.addItem("", R.drawable.ic_menu_moreoverflow_normal_holo_light);
spinner1.addItem("Test4", -1);
spinner1.setVisibleItemNo(5);
spinner1.setItemTextColor(Color.BLACK);
spinner1.setItemPadding(18, 15, 18, 15);
spinner1.setItemTextSize(20);
spinner1.setItemBackgroundColor(Color.WHITE);
spinner1.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView paramAdapterView, View paramView, int paramInt, long paramLong)
{ // TODO Auto-generated method stub
clickItem = "Center: Click item:" + paramInt; txtClick.setText(clickItem);
}
});
You can download source code from here.

Customn DropDown Spinner in Android