问题
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.
回答1:
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
来源:https://stackoverflow.com/questions/10889732/go-to-a-item-in-listview-without-using-smoothscrolltoposition