我的布局中有一个微调器,我想只选择第一个选项(索引0),无论用户选择是什么。我有一些代码,但是当微调器从用户选择快速变为索引0时,有一些文本闪烁。所以我想首先没有用户选择/选择索引0。 这是我的代码:
final Spinner onespinner = (Spinner) findViewById(R.id.spinner0);
String[] items0 = new String[] { "item 1", "item 2", "item 3","item 4","item 5" };
ArrayAdapter<String> adapter0 = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_dropdown_item, items0);
onespinner.setAdapter(adapter0);
onespinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
// automaticaly select first option
onespinner.setSelection(0,true);
// but there is some text flicker
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});