Go to a item in Listview without using smoothScrollToPosition

两盒软妹~` 提交于 2019-12-19 10:37:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!