1

这是我的问题:

我需要以R.id.spinnerfilter编程方式在我的微调器中添加许多字符串,而不是string.xml

请帮帮我

谢谢

4

2 回答 2

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);   
于 2014-05-15T09:03:54.423 回答
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);
于 2014-05-15T09:02:42.810 回答