本文整理匯總了Java中android.widget.AbsListView.OnScrollListener方法的典型用法代碼示例。如果您正苦於以下問題:Java AbsListView.OnScrollListener方法的具體用法?Java AbsListView.OnScrollListener怎麽用?Java AbsListView.OnScrollListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.widget.AbsListView
的用法示例。
在下文中一共展示了AbsListView.OnScrollListener方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setAbsListViewOnScrollListener
import android.widget.AbsListView; //導入方法依賴的package包/類
private void setAbsListViewOnScrollListener(AbsListView absListView) {
if (absListView != null) {
try {
// 通過反射獲取滾動監聽器,設置自己的滾動監聽器後通知之前已有的監聽
Field field = AbsListView.class.getDeclaredField("mOnScrollListener");
field.setAccessible(true);
// 開發者自定義的滾動監聽器
AbsListView.OnScrollListener onScrollListener = (AbsListView.OnScrollListener) field.get(absListView);
if (absListViewScrollListener == null) {
absListViewScrollListener = new AbsListViewScrollListener();
}
if (onScrollListener != absListViewScrollListener){
absListViewScrollListener.setOriginalListener(onScrollListener);
absListView.setOnScrollListener(absListViewScrollListener);
}
} catch (Exception e) {
Log.e(TAG, "反射獲取AbsListView#OnScrollListener異常", e);
}
}
}
示例2: setAbsListViewOnScrollListener
import android.widget.AbsListView; //導入方法依賴的package包/類
private void setAbsListViewOnScrollListener() {
if (mAbsListView != null) {
try {
// 通過反射獲取開發者自定義的滾動監聽器,並將其替換成自己的滾動監聽器,觸發滾動時也要通知開發者自定義的滾動監聽器(非侵入式,不讓開發者繼承特定的控件)
// mAbsListView.getClass().getDeclaredField("mOnScrollListener")獲取不到mOnScrollListener,必須通過AbsListView.class.getDeclaredField("mOnScrollListener")獲取
Field field = AbsListView.class.getDeclaredField("mOnScrollListener");
field.setAccessible(true);
// 開發者自定義的滾動監聽器
final AbsListView.OnScrollListener onScrollListener = (AbsListView.OnScrollListener) field.get(mAbsListView);
mAbsListView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView absListView, int scrollState) {
if ((scrollState == SCROLL_STATE_IDLE || scrollState == SCROLL_STATE_FLING) && shouldHandleAbsListViewLoadingMore(mAbsListView)) {
beginLoadingMore();
}
if (onScrollListener != null) {
onScrollListener.onScrollStateChanged(absListView, scrollState);
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (onScrollListener != null) {
onScrollListener.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount);
}
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例3: RecyclerToListViewScrollListener
import android.widget.AbsListView; //導入方法依賴的package包/類
public RecyclerToListViewScrollListener(AbsListView.OnScrollListener scrollListener) {
this.scrollListener = scrollListener;
}
示例4: setOnScrollListener
import android.widget.AbsListView; //導入方法依賴的package包/類
public void setOnScrollListener(AbsListView.OnScrollListener onScrollListener) {
this.onScrollListener = onScrollListener;
}
示例5: setOnScrollListener
import android.widget.AbsListView; //導入方法依賴的package包/類
public void setOnScrollListener(AbsListView.OnScrollListener onScrollListener) {
mOnScrollListener = onScrollListener;
}
示例6: makeScrollListener
import android.widget.AbsListView; //導入方法依賴的package包/類
/**
* Return ScrollListener for ListView
*
* @return OnScrollListener
*/
public AbsListView.OnScrollListener makeScrollListener() {
return new AbsListView.OnScrollListener() {
private boolean isFirstItem = false;
private boolean isLastItem = false;
@Override
public void onScrollStateChanged(AbsListView absListView, int scrollState) {
setEnabled(scrollState != AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL);
if (swipeClosesAllItemsWhenListMoves && scrollState == SCROLL_STATE_TOUCH_SCROLL) {
closeOpenedItems();
}
if (scrollState == SCROLL_STATE_TOUCH_SCROLL) {
listViewMoving = true;
setEnabled(false);
}
if (scrollState != AbsListView.OnScrollListener.SCROLL_STATE_FLING && scrollState != SCROLL_STATE_TOUCH_SCROLL) {
listViewMoving = false;
downPosition = ListView.INVALID_POSITION;
swipeListView.resetScrolling();
new Handler().postDelayed(new Runnable() {
public void run() {
setEnabled(true);
}
}, 500);
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (isFirstItem) {
boolean onSecondItemList = firstVisibleItem == 1;
if (onSecondItemList) {
isFirstItem = false;
}
} else {
boolean onFirstItemList = firstVisibleItem == 0;
if (onFirstItemList) {
isFirstItem = true;
swipeListView.onFirstListItem();
}
}
if (isLastItem) {
boolean onBeforeLastItemList = firstVisibleItem + visibleItemCount == totalItemCount - 1;
if (onBeforeLastItemList) {
isLastItem = false;
}
} else {
boolean onLastItemList = firstVisibleItem + visibleItemCount >= totalItemCount;
if (onLastItemList) {
isLastItem = true;
swipeListView.onLastListItem();
}
}
}
};
}
示例7: RecyclerToListViewScrollListener
import android.widget.AbsListView; //導入方法依賴的package包/類
public RecyclerToListViewScrollListener(AbsListView.OnScrollListener scrollListener) {
this.scrollListener = scrollListener;
}
示例8: setScrollListener
import android.widget.AbsListView; //導入方法依賴的package包/類
/**
* 設置listview的滾動監聽
*/
public void setScrollListener(AbsListView.OnScrollListener mScrollListener) {
this.mScrollListener = mScrollListener;
}
示例9: setOriginalListener
import android.widget.AbsListView; //導入方法依賴的package包/類
void setOriginalListener(AbsListView.OnScrollListener originalListener) {
this.originalListener = originalListener;
}
示例10: setOnScrollListener
import android.widget.AbsListView; //導入方法依賴的package包/類
public void setOnScrollListener(AbsListView.OnScrollListener l) {
mExternalOnScrollListener = l;
}