I want to close an Android spinner once I click outside of the Spinner. Is that even possible?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
Try
I've had some luck with this, even if it doesn't completely work.
The spinner adapter's get view :
The ontouch listener :
The on item selected listener :
The activity
Your activity with the spinner should have a global variable mOpen with get and set methods. This is because the ontouch listener tends to stay on even after the list is closed.
The limitations of this method:
It closes if you touch between the spinner and the options or to the side of the options. Touching above the spinner and below the options still won't close it.
I wanted to be able to determine when the spinner menu was displayed, and dismissed as well. After a lot of searching, there wasn't a lot of good solutions. I was able to accomplish this by doing the following:
Created a custom spinner class, and override the following method:
In my Activity, override the method onWindowFocusChanged(boolean hasFocus). If hasFocus == true && the flag in #1 is set to true, then the spinner has been dismissed (can be either by selection or tapping outside the spinner).
}
Good luck!