简体   繁体   English

Android Spinner 视图:setSelection (int position) 和 setSelection (int position, boolean animate) 之间的区别?

[英]Android Spinner view: difference between setSelection (int position) and setSelection (int position, boolean animate)?

I read the documentation, but I don't quite understand it... What is the parameter "animate" for?我阅读了文档,但我不太明白......参数“animate”是什么?

Only thing I noticed:我唯一注意到的是:

public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
{
    if (savedPosition != -1)
    {
        ((Spinner) parent).setSelection(savedPosition );
        savedPosition  = -1;
        return;
    }
   //...
}

...works fine with setSelection , but runs into endless loop / StackOverflowError with setSelection(savedPosition, true); ...使用setSelection工作正常,但使用setSelection(savedPosition, true);无限循环/ StackOverflowError setSelection(savedPosition, true);

I'm really curious why this would be so?我真的很好奇为什么会这样?

Well it should be doing what the name suggests.嗯,它应该按照名字的意思去做。 animating from the current position to the desired position.从当前位置动画到所需位置。 when you use just setSelection the change is more apropriate when you are trying to make sure the user sees the change (sort of a notification of a change) plus it looks smoother.当您只使用 setSelection 时,当您尝试确保用户看到更改(某种更改通知)时,更改更合适,而且看起来更流畅。 at least that's why i use it.至少这就是我使用它的原因。 as for the animating i never had any issues with it.至于动画我从来没有遇到过任何问题。

why are you using the savedPosition instead of position for the selection?为什么你使用savedPosition而不是位置来进行选择? maybe that's what is causing the loop.也许这就是导致循环的原因。 my suggestion is to try to do it with position and see if it fails.我的建议是尝试用位置来做,看看它是否失败。 your code is somewhat odd..你的代码有点奇怪..

ye as the comment suggested you are calling the method again for some reason because i believe the animated setSelection does that when the selection is actually set.是的,因为评论建议您出于某种原因再次调用该方法,因为我相信动画 setSelection 在实际设置选择时会这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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