Scroll ListView to position.
1 I needed to scroll the list ( ExpandableListView to be exact ) to position.1 I found this thread where Romain Guy said it got fixed in Froyo. And it is. There is a smoothscrollToPosition in SDK8 and up. As i needed to go lower than 8 here is mine workaround. If anybody knows better way let me know. 1
2 class ScrollList extends Thread { 3 4 final int position = mListView.getFlatListPosition(ExpandableListView 5 .getPackedPositionForGroup(mListAdapter.getTestGroupPosition())); 6 View itemView = mListView.getChildAt(position); 7 int yPos = itemView.getTop(); 8 public void run() { 9 while (yPos >= 20) { 10 try { 11 yPos -= 5; 12 sleep(20); 13 mListView.post(new Runnable() { 14 public void run() { 15 mListView.setSelectionFromTop(position, yPos); 16 } 17 }); 18 } catch (InterruptedException e) { 19 e.printStackTrace(); 20 } 21 } 22 } 23 };</code></pre> 24 <pre style="overflow-x: auto; overflow-y: auto; max-width: 600px; padding: 2px;"><code>
Posted via web from bytesharp | Comment »