如何從字符串數組中充填spinner?我知道在array.xml中可以這樣實現:
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);
但是如果是這樣:
String[] test=new String[]{"test1","test2"};
怎麼改變String[]
到ArrayAdapter
?
這樣用ArrayAdapter:
設置字符串數組:
String[] test=new String[]{"test1","test2"};
設置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);