As a beginner, It is difficult to bind the data to Spinner (Drop down). If we consider HTML, it is easy to add option values to the drop down. But In Android, we have to use Adapters to bind the data. So here I am targeting my approaches to bind to the Spinner.
Binding static Array to the spinner
static final String[] COUNTRIES = new String[] { "India", "US", "UK",
"Sri Lanka", "Austraila", "Denmark", "Saudi" };
Spinner spCountry = (Spinner) findViewById(R.id.spCounty);
ArrayAdapter<CharSequence> adCountry = new ArrayAdapter<CharSequence>(
this, android.R.layout.simple_spinner_dropdown_item, COUNTRIES);
adCountry.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spCountry.setAdapter(adCountry);
Binding resource Array to the Spinner
Spinner spCities = (Spinner) findViewById(R.id.spCities);
String[] cities = getResources().getStringArray(R.array.arr_cities);
ArrayAdapter<CharSequence> adCities = new ArrayAdapter<CharSequence>(
this, android.R.layout.simple_spinner_item, cities);
adCities.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spCities.setAdapter(adCities);
Binding resource Array to the Spinner Using ArrayAdapter.createFromResource
Spinner spLocalities = (Spinner) findViewById(R.id.spLocality);
ArrayAdapter<CharSequence> adLocalities = ArrayAdapter
.createFromResource(this, R.array.arr_localities,android.R.layout.simple_spinner_item);
adLocalities.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spLocalities.setAdapter(adLocalities);
References : download_source_code
http://developer.android.com/resources/tutorials/views/hello-spinner.html
http://developer.android.com/reference/android/widget/ArrayAdapter.html
Thank you so much for sharing this worth able content with us. The concept taken here will be useful for my future programs and i will surely implement them in my study. Keep blogging article like this.
Android Online Training
Well Said, you have furnished the right information that will be useful to anyone at all time. Thanks for sharing your Ideas.
software testing course in chennai
Very remarkable post! You are providing us very valid information. This is really helpful. Keep sharing.
IoT Training in Chennai
IoT Courses in Chennai
JavaScript Training in Chennai
JavaScript Course in Chennai
C C++ Training in Chennai
C Training in Chennai
IoT Training in OMR
IoT Training in Tambaram
Not only do variations in hardware and software affect the overall compatibility of the app, it reflects poorly on the build quality of the app.gerald winata gozali
Like!! I blog frequently and I really thank you for your content. The article has truly peaked my interest.