Example usage for android.widget ListView setOnScrollListener

List of usage examples for android.widget ListView setOnScrollListener

Introduction

In this page you can find the example usage for android.widget ListView setOnScrollListener.

Prototype

public void setOnScrollListener(OnScrollListener l) 

Source Link

Document

Set the listener that will receive notifications every time the list scrolls.

Usage

From source file:org.iota.wallet.helper.Utils.java

public static void fixListView(final ListView lv, final SwipeRefreshLayout swipeLayout) {
    lv.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override//from w  ww .  jav a 2s.  com
        public void onScrollStateChanged(AbsListView view, int scrollState) {

        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            int topRowVerticalPosition = (lv == null || lv.getChildCount() == 0) ? 0
                    : lv.getChildAt(0).getTop();
            swipeLayout.setEnabled(firstVisibleItem == 0 && topRowVerticalPosition >= 0);
        }
    });
}

From source file:org.solovyev.android.list.ListViewScroller.java

public static void createAndAttach(@Nonnull ListView listView, @Nonnull ListViewScrollerListener listener) {
    listView.setOnScrollListener(new ListViewScroller(listener));
}

From source file:meizhi.meizhi.malin.utils.DestroyCleanUtil.java

@SuppressLint("ObsoleteSdkInt")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static void unBindView(View view) {
    if (view == null)
        return;/*from   ww  w  .  jav  a  2  s.co m*/
    Drawable drawable;
    int i;
    //1.
    try {
        view.setOnClickListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //2.
    try {
        view.setOnCreateContextMenuListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //3.
    try {
        view.setOnFocusChangeListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //4.
    try {
        view.setOnKeyListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //5.
    try {
        view.setOnLongClickListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //6.
    try {
        view.setOnTouchListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //7.
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
            view.setOnApplyWindowInsetsListener(null);
        }
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //8.
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            view.setOnContextClickListener(null);
        }
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //9.
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            view.setOnScrollChangeListener(null);
        }
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //10.
    try {
        view.setOnDragListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //11.
    try {
        view.setOnGenericMotionListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //12.
    try {
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB_MR2) {//13
            view.setOnHoverListener(null);
        }
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //13.
    try {
        view.setOnSystemUiVisibilityChangeListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    /**
     * @see SwipeRefreshLayout#onDetachedFromWindow()
     */
    if (view.getBackground() != null && !view.getClass().getName().equals(CIRCLE_CLASS)) {
        try {
            view.getBackground().setCallback(null);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {//16
                view.setBackgroundDrawable(null);
            } else {
                view.setBackground(null);
            }
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }
    }

    //ImageView
    if (view instanceof ImageView) {
        try {
            ImageView imageView = (ImageView) view;
            drawable = imageView.getDrawable();
            if (drawable != null) {
                drawable.setCallback(null);
            }
            imageView.setImageDrawable(null);
            imageView.setImageBitmap(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }
    }

    //TextView
    if (view instanceof TextView) {
        try {
            TextView textView = (TextView) view;
            textView.setCompoundDrawables(null, null, null, null);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                textView.setCompoundDrawablesRelative(null, null, null, null);
            }
            textView.setCursorVisible(false);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }
    }

    //ImageButton
    if (view instanceof ImageButton) {
        try {
            ImageButton imageButton = (ImageButton) view;
            drawable = imageButton.getDrawable();
            if (drawable != null) {
                drawable.setCallback(null);
            }
            imageButton.setImageDrawable(null);
            imageButton.setImageBitmap(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }
    }

    //ListView
    if (view instanceof ListView) {
        ListView listView = (ListView) view;

        try {
            listView.setAdapter(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }

        try {
            listView.setOnScrollListener(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }

        try {
            listView.setOnItemClickListener(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }

        try {
            listView.setOnItemLongClickListener(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }

        try {
            listView.setOnItemSelectedListener(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }
    }

    //RecyclerView
    if (view instanceof RecyclerView) {
        try {
            RecyclerView recyclerView = (RecyclerView) view;
            recyclerView.setAdapter(null);
            recyclerView.setChildDrawingOrderCallback(null);
            recyclerView.setOnScrollListener(null);
            recyclerView.addOnScrollListener(null);
            recyclerView.removeOnScrollListener(null);
            recyclerView.setRecyclerListener(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }
    }

    //WebView
    if (view instanceof WebView) {

        WebView webView = (WebView) view;
        try {
            webView.stopLoading();
        } catch (Throwable ignored) {
            CrashReport.postCatchedException(ignored);
        }

        try {
            webView.removeAllViews();
        } catch (Throwable ignored) {
            CrashReport.postCatchedException(ignored);
        }

        try {
            webView.setWebChromeClient(null);
        } catch (Throwable ignored) {
            CrashReport.postCatchedException(ignored);
        }

        try {
            webView.setWebViewClient(null);
        } catch (Throwable ignored) {
            CrashReport.postCatchedException(ignored);
        }

        try {
            webView.destroy();
        } catch (Throwable ignored) {
            CrashReport.postCatchedException(ignored);
        }

        try {
            if (null != view.getParent() && view.getParent() instanceof ViewGroup) {
                ((ViewGroup) view.getParent()).removeView(view);
            }
        } catch (Throwable ignored) {
            CrashReport.postCatchedException(ignored);
        }

    }

    //SurfaceView
    if (view instanceof SurfaceView) {
        try {
            SurfaceView surfaceView = (SurfaceView) view;
            SurfaceHolder holder = surfaceView.getHolder();
            if (holder != null) {
                Surface surface = holder.getSurface();
                if (surface != null) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                        surface.release();
                    }
                }
            }
        } catch (Throwable ignored) {
            CrashReport.postCatchedException(ignored);
        }
    }

    view.destroyDrawingCache();
    view.clearAnimation();

    if (view instanceof ViewGroup) {
        ViewGroup viewGroup = (ViewGroup) view;
        int childCount = (viewGroup).getChildCount();
        for (i = 0; i < childCount; i++) {
            unBindView((viewGroup).getChildAt(i));
        }
    }
}

From source file:cnc.cad.mypicassso.SampleContactsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sample_contacts_activity);

    adapter = new SampleContactsAdapter(this);

    ListView lv = (ListView) findViewById(android.R.id.list);
    lv.setAdapter(adapter);/*  www. j  a v  a 2  s  . c  o  m*/
    lv.setOnScrollListener(new SampleScrollListener(this));

    getSupportLoaderManager().initLoader(ContactsQuery.QUERY_ID, null, this);
}

From source file:de.interoberlin.lymbo.view.activities.SwipeRefreshBaseActivity.java

protected void enableActionBarAutoHide(final ListView listView) {
    initActionBarAutoHide();//from   w  w  w.j av a 2 s.c  om
    listView.setOnScrollListener(new AbsListView.OnScrollListener() {
        final static int ITEMS_THRESHOLD = 1;
        int lastFvi = 0;

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            onMainContentScrolled(firstVisibleItem <= ITEMS_THRESHOLD ? 0 : Integer.MAX_VALUE,
                    lastFvi - firstVisibleItem > 0 ? Integer.MIN_VALUE
                            : lastFvi == firstVisibleItem ? 0 : Integer.MAX_VALUE);
            lastFvi = firstVisibleItem;
        }
    });
}

From source file:org.leopub.mat.controller.MessageListActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_refreshable_list);

    mUser = UserManager.getInstance().getCurrentUser();
    mBroadcastManager = LocalBroadcastManager.getInstance(this);
    mBroadcastFilter = new IntentFilter(Configure.BROADCAST_MESSAGE);
    mBroadcastReceiver = new PrivateBroadcastReceiver();

    mItemList = new ArrayList<>();
    mDataTimestamp = mUser.getLastUpdateTime();
    mItemList.addAll(getListItems());//w  w w.  j a  v  a2  s  . c o m

    mSwipeView = (SwipeRefreshLayout) findViewById(R.id.swipe);
    mSwipeView.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            mSwipeView.setRefreshing(true);
            Intent intent = new Intent(MessageListActivity.this, MessageService.class);
            intent.putExtra(MessageService.FUNCTION_TYPE, MessageService.Function.Sync);
            startService(intent);
        }
    });

    mArrayAdapter = new PrivateArrayAdapter(this, R.layout.list_item, R.id.item_content, mItemList);
    ListView listView = getListView();
    listView.setAdapter(mArrayAdapter);
    listView.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView absListView, int scrollState) {
        }

        @Override
        public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount,
                int totalItemCount) {
            View childView = absListView.getChildAt(0);
            int y = (childView == null) ? 0 : childView.getTop();
            mSwipeView.setEnabled(firstVisibleItem == 0 && y == 0);
        }
    });
}

From source file:com.anxpp.ladder.android.view.tabcarousel.demo.DummyListFragment.java

/**
 * {@inheritDoc}//from  ww w  .j a  va2 s.c om
 */
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    final ListView listView = getListView();
    listView.setOnScrollListener(new BackScrollManager(mCarousel, null, CarouselContainer.TAB_INDEX_FIRST));
    listView.setOnItemClickListener(this);
    listView.setVerticalScrollBarEnabled(false);
}

From source file:com.balieiro.facebook.FriendsListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.friends_list_fragment, container, false);
    ListView list = (ListView) view.findViewById(R.id.list_view);
    list.setAdapter(mAdapter);/* www  . j ava2s .  c om*/
    mProgress = (LinearLayout) view.findViewById(R.id.progress_layout);

    list.setOnScrollListener(new OnScrollListener() {
        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            // Load more items in the bottom of this list in case user is 
            // close to the end.
            if (totalItemCount - (firstVisibleItem + visibleItemCount) < LAZY_LOAD_LIMIT
                    && totalItemCount > 0) {
                loadItems();
            }
        }

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
        }
    });
    return view;
}

From source file:com.inovex.zabbixmobile.activities.fragments.BaseSeverityFilterListPage.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.page_severity_filter_list, null);
    //      swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipeRefreshLayout);
    //      SwipeRefreshLayout.OnRefreshListener listener = new SwipeRefreshLayout.OnRefreshListener() {
    //         @Override
    //         public void onRefresh() {
    //            ((BaseActivity) getActivity()).refreshData();
    //            swipeRefreshLayout.setRefreshing(false);
    //         }/* w  w  w.  j  av  a  2 s .c o m*/
    //      };
    //      swipeRefreshLayout.setOnRefreshListener(listener);

    final ListView listView = (ListView) rootView.findViewById(android.R.id.list);
    listView.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            final ListView lw = getListView();

            if (view.getId() == lw.getId()) {
                final int currentFirstVisibleItem = lw.getFirstVisiblePosition();

                if (currentFirstVisibleItem > mLastFirstVisibleItem) {
                    mIsScrollingUp = false;
                } else if (currentFirstVisibleItem < mLastFirstVisibleItem) {
                    mIsScrollingUp = true;
                }

                mLastFirstVisibleItem = currentFirstVisibleItem;
            }
            if (mIsScrollingUp) {
                //TODO hide subtitle-toolbar on scroll
            }
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            int topRowVerticalPosition = (listView == null || listView.getChildCount() == 0) ? 0
                    : listView.getChildAt(0).getTop();
            //            swipeRefreshLayout.setEnabled(firstVisibleItem == 0 && topRowVerticalPosition >= 0);
        }
    });
    return rootView;
}

From source file:com.google.android.demos.jamendo.app.JamendoListActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.jamendo_list);

    mAdapter = new SimpleFeedAdapter(this, getLayout(), getFrom(), getTo());
    mItems = new Loadable(getSupportLoaderManager(), LOADER_LIST,
            new StatusViewManager(this, LOADER_LIST, this, this));

    ListView listView = (ListView) findViewById(android.R.id.list);
    listView.setAdapter(new ListDecorator(mAdapter, this));
    listView.setOnItemClickListener(this);
    listView.setOnScrollListener(new ListScrollListener(mItems));

    mItems.init();//from  w  ww  .j a  v a 2  s .  c  o m
}