Created
August 27, 2015 08:11
-
-
Save VladSumtsov/e67471cd43d72acf784b to your computer and use it in GitHub Desktop.
Progress load for list view on scroll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.naughtystick.utils; | |
import android.view.View; | |
import android.widget.AbsListView; | |
import android.widget.AdapterView; | |
/** | |
* Created by dirong on 26.06.13. | |
*/ | |
public abstract class EndlessScrollListener implements AbsListView.OnScrollListener, AbsListView.OnItemSelectedListener { | |
private final AbsListView baseView; | |
private boolean active = true; | |
private int visibleThreshold; | |
protected EndlessScrollListener(AbsListView view, int visibleThreshold) { | |
this.visibleThreshold = visibleThreshold; | |
this.baseView = view; | |
view.setOnScrollListener(this); | |
view.setOnItemSelectedListener(this); | |
} | |
@Override | |
public void onScrollStateChanged(AbsListView view, int scrollState) { | |
if (scrollState == SCROLL_STATE_IDLE) { | |
if (view.getLastVisiblePosition() >= view.getCount() - visibleThreshold | |
&& active) { | |
onListEnded(); | |
} | |
} | |
} | |
public boolean isActive() { | |
return active; | |
} | |
public void setActive(boolean active) { | |
this.active = active; | |
} | |
abstract public void onListEnded(); | |
@Override | |
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { | |
} | |
public int getVisibleThreshold() { | |
return visibleThreshold; | |
} | |
@Override | |
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { | |
if (position >= baseView.getCount() - visibleThreshold && active) { | |
onListEnded(); | |
} | |
} | |
@Override | |
public void onNothingSelected(AdapterView<?> parent) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment