如何使“在所选项目上”不自动选择第一个条目
我创建了一个微调器,当有人使用阵列适配器添加设备时,它会使用设备名称自动更新。我使用微调器创建了一个 OnItemSelected 方法,因此当选择微调器中的一个名称时,会出现一个新窗口。但是,当活动启动时,OnItemSelected 会自动选择列表中的第一项,因此在新窗口出现之前,用户没有机会实际进行选择。
代码如下:
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
startActivity(new Intent("com.lukeorpin.theappliancekeeper.APPLIANCESELECTED"));
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
有谁知道一种不会自动选择列表中第一个项目的方法?
下面是微调器其余部分的代码:
ArrayAdapter<String> appliancenameadapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, ApplianceNames); //Sets up an array adapter containing the values of the ApplianceNames string array
applianceName = (Spinner) findViewById(R.id.spinner_name); //Gives the spinner in the xml layout a variable name
applianceName.setAdapter(appliancenameadapter); //Adds the contents of the array adapter into the spinner
applianceName.setOnItemSelectedListener(this);