How to populate a Spinner from Array string[]
如何从Array string []填充Spinner
Example:
例:
String[] items = new String[] {"uno", "due", "tre"};
String [] items = new String [] {“uno”,“due”,“tre”};
sp = (Spinner) findViewById(R.id.spinner);
sp <<--- ADD items Array
sp =(Spinner)findViewById(R.id.spinner); sp << --- ADD items Array
thanks
谢谢
marco
马尔科
2 个解决方案
#1
6
try this.
尝试这个。
sp.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, items));
#2
2
You would need to create a new ArrayAdapter using the String[] items as the source data and then sp.setAdapter to the newly created ArrayAdapter.
您需要使用String []项作为源数据创建新的ArrayAdapter,然后使用sp.setAdapter创建新创建的ArrayAdapter。
References:
参考文献:
- http://developer.android.com/reference/android/widget/Spinner.html
- http://developer.android.com/reference/android/widget/Spinner.html
- http://developer.android.com/reference/android/widget/ArrayAdapter.html
- http://developer.android.com/reference/android/widget/ArrayAdapter.html
#1
6
try this.
尝试这个。
sp.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, items));
#2
2
You would need to create a new ArrayAdapter using the String[] items as the source data and then sp.setAdapter to the newly created ArrayAdapter.
您需要使用String []项作为源数据创建新的ArrayAdapter,然后使用sp.setAdapter创建新创建的ArrayAdapter。
References:
参考文献:
- http://developer.android.com/reference/android/widget/Spinner.html
- http://developer.android.com/reference/android/widget/Spinner.html
- http://developer.android.com/reference/android/widget/ArrayAdapter.html
- http://developer.android.com/reference/android/widget/ArrayAdapter.html