【发布时间】:2017-03-18 02:06:33
【问题描述】:
我一直在 android studio 中进行编码,在 1 个活动中使用 2 个微调器。当我选择一个项目时,即使微调器有不同的变量,它也不会调用监听器。
以下是从数据库中填充微调器以及选择值的相关代码(在 loadSYData 函数中)
public void loadQtrData() {
Cursor cursor = myDb.getQtr();
ArrayList<String> qtrLabel = new ArrayList<>();
ArrayAdapter<String> qtrAdapter = new ArrayAdapter<String>(this, R.layout.spinner_item, qtrLabel);
qtrAdapter.setDropDownViewResource(R.layout.spinner_item);
spinnerQtrParent.setAdapter(qtrAdapter);
while(cursor.moveToNext()){
String label = cursor.getString(cursor.getColumnIndex("SC_Quarter"));
qtrLabel.add(label);
}
}
public void loadSYData(){
Cursor cursor = myDb.getSY();
ArrayList<String> syLabel = new ArrayList<>();
ArrayAdapter<String> syAdapter = new ArrayAdapter<String>(this, R.layout.spinner_item, syLabel);
syAdapter.setDropDownViewResource(R.layout.spinner_item);
spinnerSYParent.setAdapter(syAdapter);
while(cursor.moveToNext()){
String label = cursor.getString(cursor.getColumnIndex("SY"));
syLabel.add(label);
}
spinnerSYParent.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
sy = "Success";
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
我还放了一个祝酒词,说成功只是为了检查侦听器是否被调用。但是 toast 过程没有执行。
【问题讨论】: