Search code examples
androidlistviewlistviewitem

Android listview scroll


I want to move my listview one item automatically after 5 seconds. I have 10 items means 10 strings in my adapter i want to make that after 5 seconds listview automatically scroll and move to next item.


Solution

  • Without other informations is hard to help you. Anyways you could use this and add a timer that call method every 5 seconds. You should also modify the index of smoothScrollToPosition to return the right item index:

    private void scrollMyListViewToBottom() {
         myListView.post(new Runnable() {
         @Override
         public void run() {
            // Select the last row so it will scroll into view...
            listView.smoothScrollToPosition(myListAdapter.getCount() - 1);
        }
    });
    }
    

    UPDATE:

    Try to do something like this. Use a timer that call this method and be sure to put index to 0 at the end of the scroll or whenever you want:

     int index=0;//field
    
    
     private void scrollMyListviewOnebyOne() {
         myListView.post(new Runnable() {
         @Override
         public void run() {
                 listView.smoothScrollToPosition(index);
                   if(index < myListAdapter.getCount()) index ++;
    
    
        }
    });
    }