这是我的问题:
我需要在我的微调器R.id.spinnerfilter
中以编程方式添加许多字符串而不是string.xml
感谢
答案 0 :(得分:1)
这很容易做到:)
测试此代码:
Spinner spinnerfilter=(Spinner)findViewById(R.id.spinnerfilter);
ArrayList<String> spinnerarray = new ArrayList<String>();
spinnerarray.add("String1");
spinnerarray.add("String2");
spinnerarray.add("String3");
spinnerarray.add("String4");
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(yourclasshire.this, android.R.layout.simple_spinner_dropdown_item, spinnerarray);
spinnerfilter.setAdapter(spinnerArrayAdapter);
答案 1 :(得分:0)
试试这个:
String samplearray[] = {"A","B","C","D","F", "G","H","I","J"};
Spinner spinner = (Spinner) findViewById(R.id.myspinner);
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, samplearray);
spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(spinnerArrayAdapter);