i have listview witch contain 40 items and i want to write scroll listener method.i mean.when scroll position will be last item position(40th item) i would to show Toast message. i wrote some code .i can show Toast message in a last item position,but then when i scroll up i again can show Toast message this is a my source
list.setOnScrollListener(new OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
if (list.getLastVisiblePosition() == totalItemCount - 1
) {
Toast.makeText(getActivity(), "Last", Toast.LENGTH_SHORT)
.show();
try {
} catch (Exception e) {
}
}
}
});
how i can change code to can show toast message only last item position? thanks
Try this Hope it helps ..
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
if(firstVisibleItem+visibleItemCount == totalItemCount && totalItemCount!=0)
{
//your Toast
}
}