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
Binding resource Array to the Spinner
Binding resource Array to the Spinner Using ArrayAdapter.createFromResource
References : download_source_code
http://developer.android.com/resources/tutorials/views/hello-spinner.html
http://developer.android.com/reference/android/widget/ArrayAdapter.html
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.
ReplyDeleteAndroid Online Training
Very remarkable post! You are providing us very valid information. This is really helpful. Keep sharing.
ReplyDeleteIoT 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
ReplyDeleteInformative post indeed, I’ve being in and out reading posts regularly and I see alot of engaging people sharing things and majority of the shared information is very valuable and so, here’s my fine read.
ReplyDeleteclick here to continue your registration
click here to confirm
click here download
click here digital
click here download cb background
I just stumbled upon your weblog and wanted to publicize that i've without a doubt enjoyed browsing your weblog posts. 먹튀
ReplyDeleteSmm Panel
ReplyDeleteSmm panel
iş ilanları
İnstagram takipçi satın al
hirdavatciburada.com
beyazesyateknikservisi.com.tr
servis
tiktok hile