到目前为止,我一直在使用 XML 字符串数组中的微调器值,例如:
Spinner karant_sp;
karant_sp = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<CharSequence> karant_adapter = ArrayAdapter.createFromResource(this, R.array.karant_list, android.R.layout.simple_spinner_item);
karant_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
karant_sp.setAdapter(karant_adapter);
karant_sp.setSelection(0);
karant_sp.setOnItemSelectedListener(new select_karant());
我可以使用本地 java ArrayList-String 作为要在下拉菜单中显示的项目列表吗?
就像是:
Spinner karant_sp;
ArrayList<String> return_likes = new ArrayList<String>();
return_likes.add("Hello");
return_likes.add("world");
karant_sp = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<CharSequence> karant_adapter = ArrayAdapter.createFromResource(this, return_likes, android.R.layout.simple_spinner_item);
karant_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
karant_sp.setAdapter(karant_adapter);
karant_sp.setSelection(0);
karant_sp.setOnItemSelectedListener(new select_karant());
我知道上面的代码不起作用,但我想知道一些使用 ArrayList-string 的东西。