final Spinner spinner = (Spinner) findViewById(R.id.spinner1);
通过
填充微调器static final String[] Months = new String[] { "January", "February",
"March", "April", "May", "June", "July", "August", "September",
"October", "November", "December" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, Months);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
用于停止微调器运行时程序
1 - 代码
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
protected boolean inhibit_spinner = false;
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
if (inhibit_spinner == true) {
//////////////////go to function///////////////
}
inhibit_spinner = true;
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {}
});
2 - 代码
spinner.post(new Runnable() {
@Override
public void run() {
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
/////////////go to function///////////////
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}});
}
});
**为什么选择“1月”不运行功能**
1月是微调器中的frist项目
是微调器是一个项目还是选择项目首先是微调器中的默认值如果程序不是第一选择则再次选择第一个项目
(选择第一项spiner后运行功能)
如果首先选择项目“1月”不去功能(如果我们选择不去功能,1月第一个选项是运行相同的)???????