How can i populate a Spinner from String array
, I know i can do that from array.xml
like this code
:
ArrayAdapter<CharSequence> gameKindArray = ArrayAdapter.createFromResource(view.getContext(),R.array.game_kind, android.R.layout.simple_spinner_item);
gameKindArray.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
gameKind.setAdapter(gameKindArray);
but when i have
String[] test=new String[]{"test1","test2"};
how i can change String[]
to ArrayAdapter
?!
Use ArrayAdapter this way
your string array
String[] test=new String[]{"test1","test2"};
your ArrayAdapter
ArrayAdapter<String> gameKindArray= new ArrayAdapter<String>(MyActivityClass.this,android.R.layout.simple_spinner_item, test);
gameKindArray.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
gameKind.setAdapter(gameKindArray);