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.

24 comments:

  1. it's very useful blog fr me thank you for sharing the information....

    Financial industry regulation|FCA compliance|FCA assistance

    ReplyDelete
  2. 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
  3. This comment has been removed by the author.

    ReplyDelete
  4. Nice blog..! I really loved reading through this article... Thanks for sharing such an amazing post with us and keep blogging...
    Feels free to get amazing update regarding SSC 2018 and south results SSLC 2018

    ReplyDelete
  5. To get the information regarding SSLC results 2018 SSLC Result Please go through this link


    We will get the Karnataka SSLC Results on instantKarnataka SSLC ResultBy just clicking this link


    Very nice to here the information of Kerala SSLC Results are availableKerala SSLC ResultOn your fingertip


    Entire Tamil SSLC Results are ready on your screenTamilnadu SSLC Result Please click on this link

    ReplyDelete
  6. We will get all information regarding the Kerala SSLC results 2018kerala sslc resultsPlease click on this link

    ReplyDelete
  7. We will get complete information of Tamilnadu HSC Results 2018tamilnadu hsc results 2018Just click on this link

    ReplyDelete
  8. We will get complete information of Tamilnadu SSLC Results 2018tamilnadu sslc results 2018Just click on this link

    ReplyDelete
  9. We will get complete and detailed information of Kerala Plus Two Results 2018Kerala Plus Two Results 2018On a simple on this link

    ReplyDelete
  10. We will get complete and detailed information of Kerala DHSC Results 2018Kerala DHSC Results 2018On a simple on this link

    ReplyDelete
  11. Nice blog ..! I really loved reading through this article.. Thanks for sharing such a amazing post with us and keep blogging...
    phonegap services in hyderabad

    ReplyDelete
  12. Very nice blog. Very informative. Limra Technosys is leading mobile app development company in Mumbai

    ReplyDelete
  13. I was recommended this web site by means of my cousin.
    I am now not certain whether this post is written through him as nobody else recognise such precise about my difficulty. You're amazing! Thank you!

    selenium training in Chennai
    selenium training in Tambaram
    selenium training in Velachery
    selenium training in Omr
    selenium training in Annanagar


    After reading this web site I am very satisfied simply because this site is providing comprehensive knowledge for you to audience.
    Thank you to the perform as well as discuss anything incredibly important in my opinion. We loose time waiting for your next article writing in addition to I beg one to get back to pay a visit to our website in

    ReplyDelete
  14. You blog post is just completely quality and informative. Many new facts and information which I have not heard about before. Keep sharing more blog posts.
    Python Online training
    python Course institute in Chennai
    Python Course institute in Bangalore

    ReplyDelete
  15. Informative post.i learn many new things from your post it will help in my Mobile Application development company in Nagpur

    ReplyDelete
  16. Very Informative and helpful blog. prolifiquetech is leading android development company in mumbai

    ReplyDelete
  17. I really enjoy simply reading all of your weblogs. Simply wanted to inform you that you have people like me who appreciate your work. Definitely a great post I would like to read this
    Digital Marketing Company in mumbai
    Digital Marketing agency in Mumbai

    ReplyDelete
  18. Nice work. Thank you for sharing the information.
    moviebox for pc


    ReplyDelete
  19. Thanks for sharing
    Unicsol is a Custom Software Development Company in Hyderabad that provides value-added software services by turning bytes into business by our deligent team

    ReplyDelete