In this blog i will tell u how u can create spinner in Android by local String Array.
I want to show all countries data in spinner .
1.First take countries data in String.xml as below copy that
2.create a spinner in activity_main_xml
3.define a spinner -
private Spinner spinner;
5.find this spinner by its id-
spinner=(Spinner)findViewById(R.id.spinner);
6.define a string Array for country data-
String[] country;
7.now get resource of country from xml file-
country =getResources().getStringArray(R.array.countries_array);
8.now create a adapter-
ArrayAdapter<String> adapter = new
ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,country);
9.after that set value to spinner of adapter-
spinner.setAdapter(adapter);
final MainActivity.java look like below-
hope this blog will helpful for you.
Full Project Code- Click Here
0 Comments