onItemSelectedListener
在我的主要活动中,我有一个用于微调的功能。我将侦听器分配给onCreate
Method中的Spinner对象。
活动类具有成员变量int iCurrentSelection
。但是无论我iCurrentSelection
在活动中的任何地方设置什么,在onItemSelected
Method中它始终为null 。因此,即使没有任何变化,布尔值changed
始终true
是。
我不明白为什么!有人请启发我:-)
这是我的侦听器类:
OnItemSelectedListener oisl = new OnItemSelectedListener(){
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
boolean changed = iCurrentSelection != arg0.getSelectedItemPosition();
stopTracks();
if(changed){
iCurrentSelection = arg0.getSelectedItemPostion();
initTracks(actSpeed);
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
}
活动类具有成员变量“ int iCurrentSelection”。但是无论我将iCurrentSelection设置为活动中的任何位置,它始终为null
在Java中,int值永远不会为Null,我不认为存在问题!也许arg0.getSelectedItemPosition()的返回为Null!因此将整数值与Null对象进行比较将返回Null!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句