转到列表视图一个项目,而无需使用smoothScrollToPosition [英] Go to a item in Listview without using smoothScrollToPosition
问题描述
我希望去(显示)一个具体项目在我的列表视图,但没有滚动。我不希望任何动画,但我想在瞬间输送到所需的项目。
我使用的是可检查的列表视图: mylistview.setChoiceMode(1)
我明白了 mylistview.setSelection(位置)
是解决方案,但是当我使用它,什么都不会发生(也许是因为它是一个可检查的列表视图?)。
当我使用 mylistview.smoothScrollToPosition(位置)
,它运作良好,但我有很明显这滚动的动画,我不想要的。
我能做什么?
感谢。
尝试了这一点:
myListView.post(新的Runnable()
{
@覆盖
公共无效的run()
{
myListView.setSelection(POS)
视图V = myListView.getChildAt(POS)
如果(V!= NULL)
{
v.requestFocus();
}
}
});
从罗曼盖伊链接 谷歌这样开发者邮件列表的答案p>
I'd like to go to (display) a specific item in my listview but without scrolling. I don't want any animation but I'd like to be instantaneously transported to the desired item.
I'm using a checkable listview : mylistview.setChoiceMode(1)
.
I understood that mylistview.setSelection(position)
is the solution, but when I use it, nothing happens (maybe because it's a checkable listview ?).
When I use mylistview.smoothScrollToPosition(position)
, it works well but I have obviously this scroll animation which I don't want.
What could I do ?
Thanks.
Try this out:
myListView.post(new Runnable()
{
@Override
public void run()
{
myListView.setSelection(pos);
View v = myListView.getChildAt(pos);
if (v != null)
{
v.requestFocus();
}
}
});
From this Google Developer list answer by Romain Guy Link
这篇关于转到列表视图一个项目,而无需使用smoothScrollToPosition的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!