如何判断滚动是向上还是向下?
如果gridview滚动顶部或底部,我想删除所有数据并重新加载其他数据,但我不知道如何获取向上或向下滚动状态?我尝试使用
@Override
public boolean onTouchEvent(MotionEvent event)
获取状态,但 onTouchEvent
未运行。
mygridview.setOnScrollListener(new OnScrollListener()
{
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount)
{
}
public void onScrollStateChanged(AbsListView view, int scrollState)
{
switch (scrollState)
{
case OnScrollListener.SCROLL_STATE_TOUCH_SCROLL:
if (photolist_scroll_flag == 0) //scroll up
{
if (has_loaded_item - page_item_num > 0)
{
LoadRemainingItems();
}
}
else if (photolist_scroll_flag == 1) //scroll down
{
if (lastItem == view.getCount())
{
if (has_loaded_item < listtotalitem)
{
LoadRemainingItems();
}
}
}
break;
case OnScrollListener.SCROLL_STATE_FLING:
break;
case OnScrollListener.SCROLL_STATE_IDLE:
break;
}
}
});
If gridview scroll top or bottom, I want to remove all data and reload other data but I don't know how to get the scroll up or down status? I try to use
@Override
public boolean onTouchEvent(MotionEvent event)
get the status, but onTouchEvent
is not run.
mygridview.setOnScrollListener(new OnScrollListener()
{
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount)
{
}
public void onScrollStateChanged(AbsListView view, int scrollState)
{
switch (scrollState)
{
case OnScrollListener.SCROLL_STATE_TOUCH_SCROLL:
if (photolist_scroll_flag == 0) //scroll up
{
if (has_loaded_item - page_item_num > 0)
{
LoadRemainingItems();
}
}
else if (photolist_scroll_flag == 1) //scroll down
{
if (lastItem == view.getCount())
{
if (has_loaded_item < listtotalitem)
{
LoadRemainingItems();
}
}
}
break;
case OnScrollListener.SCROLL_STATE_FLING:
break;
case OnScrollListener.SCROLL_STATE_IDLE:
break;
}
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论