Search code examples
androidandroid-listviewscrollbar

Hide scrollbar when scrolling listview programmatically?


I made a chat application and have Chat Activity in it. To display messages in dialog-like style I use ListView.

When I receive or send message to chat I need ListView to scroll down to it's end. Now I doing it with

chatView.smoothScrollToPosition(chatAdapter.getCount());

But when listview scrolls down it shows an animated vertical scrollbar. However. I want to display the vertical scrollbar when a user scrolls the list by himself (using finger) and NOT show the scrollbar when I do it programmatically.

How can I achieve that?


Solution

  • Before you scroll the list programmatically, do this:

    myListView.setVerticalScrollBarEnabled(false);
    

    After, do this:

    myListView.setVerticalScrollBarEnabled(true);
    

    This will hide / show the scrollbar when (don't) you want it.