Undesired onItemSelected calls

后端 未结 5 1007
半阙折子戏
半阙折子戏 2020-12-02 19:04

I have 36 spinners that I have initialized with some values. I have used onItemSelectedListener with them. As usual, the user can interact with these spinners, firing the on

5条回答
  •  隐瞒了意图╮
    2020-12-02 19:47

    I don't know if this solution is as foolproof as the chosen one here, but it works well for me and seems even simpler:

    boolean executeOnItemSelected = false;
    spinner.setSelection(pos)
    

    And then in the OnItemSelectedListener

    public void onItemSelected(AdapterView parent, View view, int position, long id) {
        if(executeOnItemSelected){
            //Perform desired action
        } else {
            executeOnItemSelected = true;
        }
    }
    

提交回复
热议问题