Go to a item in Listview without using smoothScrol

2019-02-19 10:23发布

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条回答
淡お忘
2楼-- · 2019-02-19 11:22

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

查看更多
登录 后发表回答