Skip to content Skip to sidebar Skip to footer

How To Populate A Spinner From String Array

How can i populate a Spinner from String array , I know i can do that from array.xml like this code : ArrayAdapter gameKindArray = ArrayAdapter.createFromResour

Solution 1:

Use ArrayAdapter this way

your string array

String[] test=newString[]{"test1","test2"};

your ArrayAdapter

ArrayAdapter<String> gameKindArray= newArrayAdapter<String>(MyActivityClass.this,android.R.layout.simple_spinner_item, test);
   gameKindArray.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
   gameKind.setAdapter(gameKindArray); 

Solution 2:

Try the below

ArrayAdapter<String> gameKindArray =  newArrayAdapter<String>(this,
                android.R.layout.simple_spinner_item, test);   
     gameKind.setAdapter(adapter);

For more info check the docs.

http://developer.android.com/reference/android/widget/ArrayAdapter.html

http://developer.android.com/reference/android/widget/Spinner.html

Solution 3:

you dont need to convert in any form just use your string array like below:

ArrayAdapter<String> gameKindArray= newArrayAdapter<String>(MyActivityClass.this,android.R.layout.simple_spinner_item, test);
   gameKindArray.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
   gameKind.setAdapter(gameKindArray); 

you can get easily into spinner.

Post a Comment for "How To Populate A Spinner From String Array"