简体   繁体   中英

Android Spinner.setSelection(int, false) creates messed up Spinners

after using setSelection(int, false) like suggested here because i had troubles using the default setSelection(int) for initial setup it turns out that using the two param version messes up the spinner layout till the first manual selection takes place, details see image below. Is there a way to "update" the spinner layout?

setSelection 2param弄乱了微调器的布局

Okay i got it. I extedned the Spinner Class, added a var for saveing that this is the "first" pass and have overrwitten the onDraw method. after super.OnDraw() is called i can be sure that the layout has been drawn the first time and all data is passed to the spinner so to following requestLayout() will fix any layout errors. so i just test if this is the first onDraw with my var, if so i call requestLayout() and set the var to false. it's not the best way and maybe there is another event i could use that is run bevore the draw happens, but it's good enough for my needs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM