1

在我的主要活动中,我的 Spinner有一个onItemSelectedListener。我将侦听器分配给onCreate方法中的微调器对象。

活动类有一个成员变量int iCurrentSelection。但无论我iCurrentSelection在活动中的任何位置设置什么,它在方法中始终为空onItemSelected。因此,即使没有任何变化,布尔值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) {
    }
}
4

1 回答 1

0

活动类有一个成员变量“int iCurrentSelection”。但无论我将 iCurrentSelection 设置为活动中的任何位置,它始终为空

在 Java 中, int 值永远不会是 Null ,我认为问题不存在!也许 arg0.getSelectedItemPosition() 的返回是 Null!因此将整数值与 Null 对象进行比较将返回 Null!

于 2013-10-19T08:42:51.273 回答