ignore OnItemSelectedListener firing on create

后端 未结 5 1519
悲&欢浪女
悲&欢浪女 2021-02-19 06:48

I\'m creating a spinner and I\'ve added an OnItemSelectedListener to it. However I\'ve noticed that it fires on create. Now I was wondering if there wa

5条回答
  •  我寻月下人不归
    2021-02-19 07:03

    Well I think I found nice solution for me, I had it in mind from start but... I have custom wrapper class based on android Handler , that is called DoLater, and also there is custom Adapter based on Listener so you cant copy paste this but you will get idea. Dangerous thing is just that somehow delay 500 can be to long and View can be already destroyed (when user do some wired stuff quickly or phone gets slow...) so DoLater cares of that so it is not called when activity is not resumed. But this way OnItemSelectedListener is not fired on create.

    public void onResume() {
        super.onResume();
        new DoLater(this, 500) {
                    public void run() {
                        new OnSpinnerSelectedAdapter(getBowSpinner()) {
                            protected void onItemSelected(int position) {
                                onBowSelected(position);
                            }
                        };
                    }
                };
    }
    

提交回复
热议问题