你如何从Java $ C $填补了微调ç编程?
我在这样的布局中的微调:
<微调
机器人:ID =@ + ID / consultation_deseases
机器人:layout_width =@扪/ bigSpinnerWidth
机器人:layout_height =@扪/ bigSpinnerHeight
机器人:提示=@字符串/ disease_prompt/>
与Java code,我需要创建适配器并添加物品。
解决方案 //你需要有你想要的微调来显示数据列表
名单<字符串> spinnerArray =新的ArrayList<字符串>();
spinnerArray.add(ITEM1);
spinnerArray.add(项目2);
ArrayAdapter<字符串>适配器=新的ArrayAdapter<字符串>(
对此,android.R.layout.simple_spinner_item,spinnerArray);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
微调sItems =(微调)findViewById(R.id.spinner1);
sItems.setAdapter(适配器);
也找出被选中,你可以做这样的事情
字符串选择= sItems.getSelectedItem()的toString()。
如果(selected.equals(什么都可以选择是)){
}
How do you fill a spinner from java code programmatically?
I have a spinner in the layout like this:
<Spinner
android:id="@+id/consultation_deseases"
android:layout_width="@dimen/bigSpinnerWidth"
android:layout_height="@dimen/bigSpinnerHeight"
android:prompt="@string/disease_prompt" />
With java code I need to create the adapter and add the items.
解决方案// you need to have a list of data that you want the spinner to display
List<String> spinnerArray = new ArrayList<String>();
spinnerArray.add("item1");
spinnerArray.add("item2");
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
this, android.R.layout.simple_spinner_item, spinnerArray);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Spinner sItems = (Spinner) findViewById(R.id.spinner1);
sItems.setAdapter(adapter);
also to find out what is selected you could do something like this
String selected = sItems.getSelectedItem().toString();
if (selected.equals("what ever the option was")) {
}
上一篇:运行使用32位COM一个64位的Windows机器上的32位应用程序应用程序、机器上、COM、Windows
下一篇:ArrayAdapter,BaseAdapter和ListAdapter之间的区别是什么区别、ArrayAdapter、BaseAdapter、ListAdapter