2 lpploverou LPPloveROU 于 2013.06.26 17:04 提问

从字符串数组中充填spinner

如何从字符串数组中充填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

1个回答

ce_la_vie
ce_la_vie   2013.06.26 17:27
已采纳

这样用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); 
Csdn user default icon
上传中...
上传图片
插入图片