OnItemSelectedListener 在屏幕旋转时调用 [英] OnItemSelectedListener called on screen rotation

查看:71
本文介绍了OnItemSelectedListener 在屏幕旋转时调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在 Android 中更改屏幕方向时,会调用来自 Spinner 的 OnItemSelectedListener.

When I change the orientation of my screen in Android, an OnItemSelectedListener from a Spinner is called.

这不仅仅是模拟器,它也发生在实体手机上.

It's not just the emulator, it also happens on a physical phone.

我怎样才能阻止这种情况发生?

How can I stop this from occurring?

干杯.

推荐答案

Spinners 总是被选中.当 Spinner 的状态发生任何变化时,包括第一次设置 Spinner 时,您的 OnItemSelectedListener 将被调用.正常的方向更改将导致您的活动被破坏和重新创建.因此,如果您的 OnItemSelectedListener 在您的 Activity 首次出现在屏幕上时被调用,则在更改方向时将再次调用它.

Spinners are always selected. Your OnItemSelectedListener will be called when there is any change in the state of the Spinner, including when the Spinner is first set up. A normal orientation change will result in your activity being destroyed and recreated. So, if your OnItemSelectedListener is being called when your activity is first appearing on the screen, it will be called again when the orientation is changed.

我怎样才能阻止这种情况发生?

How can I stop this from occurring?

setAdapter() 相比,您或许可以调整调用 setOnItemSelectedListener() 的时间,看看是否有帮助.

You might be able to play around with the timing of when you call setOnItemSelectedListener() compared to setAdapter(), to see if it helps.

这篇关于OnItemSelectedListener 在屏幕旋转时调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆