Android:ListView
lastmod 2014-03-17created 2014-01-083 edits
Remembering the current ListView position and moving the Scroll
How to get the current position of a ListView as an INDEX, and how to move to that INDEX, is shown below.
// 현재 위치(INDEX) 획득.
int position = listView.getFirstVisiblePosition();
// 해당 INDEX 이동.
ListView.setSelection(position);
Height of ListView
You can get the height of a list view by combining the functions below.
-
ListView.getChildCount(): number of child views currently shown on screen in the list view. -
ListView.getChildAt(index): only the child views currently shown on screen in the list view can be controlled by index. -
ListView.getChildAt(index).getHeight(): height of a child view.
Forced ListView scrolling
Use the smoothScrollBy function as follows.
ListView listView;
// ...
/** <code>y</code>만큼 스크롤한다. */
public void scrollCattingListBy(int y) {
Assert.assertNotNull(listView);
final int SCROLL_DURATION = 200;
listView.smoothScrollBy(y, SCROLL_DURATION);
}