Monday, 5 August 2013

Customn DropDown Spinner in Android

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:

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 : 

  setOnItemClickListener

  setOnItemSelectedListener


 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.

11 comments:

  1. Wiztech Automation is the Leading Best IEEE Final year project Centre in Chennai and the final year students are provided complete guidance and support in their final year projects. The IEEE projects in Chennai that Wiztech Automation offers guidance and support for include complete range of system domains – such as PLC projects, embedded projects, VLSI projects, software projects, IT projects, Civil projects. Students looking for specific projects pertaining to departments of ECE, EEE, E&I, Mechanical, Mechatronics, bio-medical, IT, Computer, Civil projects in B.E, M.E, B.Tech, M.Tech, B.SC., and M.Sc Electronics, could also get turnkey solutions at Wiztech Automation Solutions to turn out successful project outcomes and models. Since the students at Wiztech Automation gain thorough theoretical and practical knowledge and skills as they pursue their final year projects and develop 2015 and 2016 Latest IEEE Projects portraying them well.

    Final year projects in chennai
    Mechanical projects in chennai
    ece projects in chennai
    Final year eee projects in chennai
    VLSI project center in chennai
    Industrial projects in chennai
    Fianl year CSE projects in chennai

    ReplyDelete
  2. WIZTECH Automation, Anna Nagar, Chennai, has earned reputation offering the best automation training in Chennai in the field of industrial automation. Flexible timings, hands-on-experience, 100% practical. The candidates are given enhanced job oriented practical training in all major brands of PLCs (AB, Keyence, ABB, GE-FANUC, OMRON, DELTA, SIEMENS, MITSUBISHI, SCHNEIDER, and MESSUNG)

    PLC training in chennai
    Automation training in chennai
    Best plc training in chennai
    PLC SCADA training in chennai
    Process automation training in chennai
    Final year eee projects in chennai
    VLSI training in chennai

    ReplyDelete
  3. Embedded system training: Wiztech Automation Provides Excellent training in embedded system training in Chennai - IEEE Projects - Mechanical projects in Chennai Wiztech provide 100% practical training, Individual focus, Free Accommodation, Placement for top companies. The study also includes standard microcontrollers such as Intel 8051, PIC, AVR, ARM, ARMCotex, Arduino etc.

    Embedded system training in chennai
    Embedded Course training in chennai
    Matlab training in chennai
    Android training in chennai
    LabVIEW training in chennai
    Arduino training in chennai
    Robotics training in chennai
    Oracle training in chennai
    Final year projects in chennai
    Mechanical projects in chennai
    ece projects in chennai

    ReplyDelete
  4. Thank you for the info. It sounds pretty user friendly. I guess I’ll pick one up for fun. thank u

    Google App Integration Chennai

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. This information is impressive; I am inspired with your post writing style & how continuously you describe this topic. After reading your post, thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic.android development course fees in chennai | android app development training in chennai

    ReplyDelete