Android App Development
iOS App Development
Flutter App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 18.104.22.168 release ready!
Updated 15 December 2016
Spinners in android provide a quick way to select one value from a set of predefined values. But the most cmplecated part is how to pass those values to the android and especially when the data is dynamic.
So here we will learn how to add our data to spinner whether its static or dynamic. Firstly we have to declare the spinner in our activity whether in layout.XML file or programatically, its your choice whatever suits you better. The we have to add the adapter that contains our data.
The static data is easy to add just go to res/values folder and search for arrays.xml file , if its not there create one with the tag <resources> now in this file you can add your data as array forexample:
Now you can use these arrays in your spinner with the following code:
And your spinner is ready to use but the situation complicates where you have dynamic data from a site and then you want to shoe that data in spinner.
Dynamic data can be in various forms like List, Map, etc. so we need a way to deal with it. Actually its quite simple just save your data in one of these and then you can convert them to simple array and use them.
Now add your array to spinner
Thats it and your spinner is ready to use. To set listener in spinner add onItemSelectedListener and put the functionality you want to get in the listener.
You can also add dependent spinners like I did below.
Your email address will not be published. Required fields are marked*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.