First you must calculate the position (position means, position of first contact starting with "b" in ArrayList
). For that you can store the number of contacts starting with "a", "b" and so on in an ArrayList
.
So suppose on swipe you want to jump to the first contact starting with "b", then its position in the ArrayList
is equal to the number of contacts starting with "a".
Now we have the position we want to jump to. I assume that osList
is your ListView
.
First calculate the number of views that can be occupied on screen. For that we need to calculate
pos1
, which is the position of Top Visible View on screen andpos2
, which is the position of Last Visible View on screen:pos1 = osList.getFirstVisiblePosition() pos2 = osList.getLastVisiblePosition()
Now the number of views that can be occupied (not accurate) on screen is
numScreenViews = pos2 - pos1 - 1
. here -1 is to eliminate the possibility that any view is partially visible. After all we have a rough idea.Now inside
osSwipeRight()
:public void onSwipeRight() { osList.smoothScrollToPostion(min(noOfContact -1, position + numScreenViews)); }
You don't need to use
getChildAt()
here, however if you want to get the posOnScreen(I am calling itposOnScreen
because it's not the position in theArrayList
as clarified by @Joel) of first visible contact starting with "b", again calculatepos1
, then calculateposOnScreen
= position of your view (here position of first contact starting with alphabet "b" in arrayList) - pos1.