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.getlantern.firetweet.fragment.support.BaseSupportListFragment.java

/**
 * Provide default implementation to return a simple list view. Subclasses
 * can override to replace with their own layout. If doing so, the returned
 * view hierarchy <em>must</em> have a ListView whose id is
 * {@link android.R.id#list android.R.id.list} and can optionally have a
 * sibling view id {@link android.R.id#empty android.R.id.empty} that is to
 * be shown when the list is empty./* w ww .  j  av a2  s  .c o m*/
 * <p/>
 * <p/>
 * If you are overriding this method with your own custom content, consider
 * including the standard layout {@link android.R.layout#list_content} in
 * your layout file, so that you continue to retain all of the standard
 * behavior of ListFragment. In particular, this is currently the only way
 * to have the built-in indeterminant progress state be shown.
 */
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    final Context context = getActivity();

    final FrameLayout root = new FrameLayout(context);

    // ------------------------------------------------------------------

    final LinearLayout pframe = new LinearLayout(context);
    pframe.setId(INTERNAL_PROGRESS_CONTAINER_ID);
    pframe.setOrientation(LinearLayout.VERTICAL);
    pframe.setVisibility(View.GONE);
    pframe.setGravity(Gravity.CENTER);

    final ProgressBar progress = new ProgressBar(context, null, android.R.attr.progressBarStyleLarge);
    pframe.addView(progress, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    root.addView(pframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    // ------------------------------------------------------------------

    final ExtendedFrameLayout lframe = new ExtendedFrameLayout(context);
    lframe.setId(INTERNAL_LIST_CONTAINER_ID);
    lframe.setTouchInterceptor(mInternalOnTouchListener);

    final TextView tv = new TextView(getActivity());
    tv.setTextAppearance(context, ThemeUtils.getTextAppearanceLarge(context));
    tv.setId(INTERNAL_EMPTY_ID);
    tv.setGravity(Gravity.CENTER);
    lframe.addView(tv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    final ListView lv = new ListView(getActivity());
    lv.setId(android.R.id.list);
    lv.setDrawSelectorOnTop(false);
    lv.setOnScrollListener(this);
    lframe.addView(lv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    root.addView(lframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    // ------------------------------------------------------------------

    root.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    return root;
}

From source file:com.achep.header2actionbar.HeaderFragmentSupportV4.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Activity activity = getActivity();
    assert activity != null;
    mFrameLayout = new FrameLayout(activity);

    mHeader = onCreateHeaderView(inflater, mFrameLayout);
    mHeaderHeader = mHeader.findViewById(android.R.id.title);
    mHeaderBackground = mHeader.findViewById(android.R.id.background);
    assert mHeader.getLayoutParams() != null;
    mHeader.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
            View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
    mHeaderHeight = mHeader.getMeasuredHeight();

    mFakeHeader = new Space(activity);

    View content = onCreateContentView(inflater, mFrameLayout);
    mContentView = content;//from w  ww  . ja va  2s  . c om
    Log.i(TAG, "container:" + container.getMeasuredHeight() + ",mHeaderHeight=" + mHeaderHeight);

    final View topContentView = container;

    if (content instanceof ListView) {
        isListViewEmpty = true;

        final ListView listView = (ListView) content;
        mFakeHeader.setLayoutParams(new ListView.LayoutParams(0, mHeaderHeight));
        listView.addHeaderView(mFakeHeader);
        listView.setOnScrollListener(new AbsListView.OnScrollListener() {

            @Override
            public void onScrollStateChanged(AbsListView absListView, int scrollState) {
                if (mOnScrollListener != null) {
                    mOnScrollListener.onScrollStateChanged(absListView, scrollState);
                }
            }

            @Override
            public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount,
                    int totalItemCount) {
                if (isListViewEmpty) {
                    scrollHeaderTo(0);
                } else {
                    final View child = absListView.getChildAt(0);
                    assert child != null;
                    scrollHeaderTo(child == mFakeHeader ? child.getTop() : -mHeaderHeight);
                }
            }
        });
    } else {
        topContentView.getViewTreeObserver()
                .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                    @SuppressWarnings("deprecation")
                    @Override
                    public void onGlobalLayout() {
                        //Remove it here unless you want to get this callback for EVERY
                        //layout pass, which can get you into infinite loops if you ever
                        //modify the layout from within this method.
                        topContentView.getViewTreeObserver().removeGlobalOnLayoutListener(this);

                        //Now you can get the width and height from content
                        int actionBarHeight = 0;
                        TypedValue tv = new TypedValue();
                        if (getActivity().getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
                            actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,
                                    getResources().getDisplayMetrics());
                        }
                        Log.i(TAG, "topContentView:" + topContentView.getHeight() + ", actionBarHeight:"
                                + actionBarHeight + ", getStatusBarHeight:" + getStatusBarHeight());
                        ViewGroup.LayoutParams lp = mContentView.getLayoutParams();
                        lp.height = topContentView.getHeight() - actionBarHeight - getStatusBarHeight();
                        mContentView.setLayoutParams(lp);
                    }
                });

        // Merge fake header view and content view.
        final LinearLayout view = new LinearLayout(activity);
        view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        view.setOrientation(LinearLayout.VERTICAL);
        mFakeHeader.setLayoutParams(new LinearLayout.LayoutParams(0, mHeaderHeight));
        view.addView(mFakeHeader);
        view.addView(content);

        // Put merged content to ScrollView
        final NotifyingScrollView scrollView = new NotifyingScrollView(activity);
        scrollView.addView(view);
        scrollView.setVerticalScrollBarEnabled(false);
        scrollView.setOverScrollMode(ScrollView.OVER_SCROLL_NEVER);
        scrollView.setOnScrollChangedListener(new NotifyingScrollView.OnScrollChangedListener() {
            @Override
            public void onScrollChanged(ScrollView who, int l, int t, int oldl, int oldt) {
                Log.i(TAG, "onScrollChanged scroll ot -t :" + (-t));
                scrollHeaderTo(-t);
            }
        });
        mContentWrapper = scrollView;
        content = scrollView;
    }

    mFrameLayout.addView(content);
    mFrameLayout.addView(mHeader);

    // Content overlay view always shows at the top of content.
    if ((mContentOverlay = onCreateContentOverlayView(inflater, mFrameLayout)) != null) {
        mFrameLayout.addView(mContentOverlay, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
    }

    // Post initial scroll
    mFrameLayout.post(new Runnable() {
        @Override
        public void run() {
            Log.i(TAG, "post initial scroll to 0");
            // SEAN: walk around for scroll position bug
            if (mContentWrapper != null) {
                mContentWrapper.scrollTo(0, 0);
            }
            scrollHeaderTo(0, true);
        }
    });

    return mFrameLayout;
}

From source file:com.utils.widget.head.HeaderFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Activity activity = getActivity();
    assert activity != null;
    mFrameLayout = new FrameLayout(activity);

    mHeader = onCreateHeaderView(inflater, mFrameLayout);
    mHeaderHeader = mHeader.findViewById(android.R.id.title);
    mHeaderBackground = mHeader.findViewById(android.R.id.background);
    assert mHeader.getLayoutParams() != null;
    mHeaderHeight = mHeader.getLayoutParams().height;
    mFakeHeader = new Space(activity);
    mFakeHeader.setLayoutParams(new ListView.LayoutParams(0, mHeaderHeight));

    View content = onCreateContentView(inflater, mFrameLayout);
    if (content instanceof ListView) {
        isListViewEmpty = true;/*from www  .  j ava 2 s.  c  om*/

        final ListView listView = (ListView) content;
        listView.addHeaderView(mFakeHeader);
        listView.setOnScrollListener(new AbsListView.OnScrollListener() {

            @Override
            public void onScrollStateChanged(AbsListView absListView, int scrollState) {
                if (mOnScrollListener != null) {
                    mOnScrollListener.onScrollStateChanged(absListView, scrollState);
                }
            }

            @Override
            public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount,
                    int totalItemCount) {
                if (mOnScrollListener != null) {
                    mOnScrollListener.onScroll(absListView, firstVisibleItem, visibleItemCount, totalItemCount);
                }

                if (isListViewEmpty) {
                    scrollHeaderTo(0);
                } else {
                    final View child = absListView.getChildAt(0);
                    assert child != null;
                    scrollHeaderTo(child == mFakeHeader ? child.getTop() : -mHeaderHeight);
                }
            }
        });
    } else {

        // Merge fake header view and content view.
        final LinearLayout view = new LinearLayout(activity);
        view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        view.setOrientation(LinearLayout.VERTICAL);
        view.addView(mFakeHeader);
        view.addView(content);

        // Put merged content to ScrollView
        final NotifyingScrollView scrollView = new NotifyingScrollView(activity);
        scrollView.addView(view);
        scrollView.setOnScrollChangedListener(new NotifyingScrollView.OnScrollChangedListener() {
            @Override
            public void onScrollChanged(ScrollView who, int l, int t, int oldl, int oldt) {
                scrollHeaderTo(-t);
            }
        });
        content = scrollView;
    }

    mFrameLayout.addView(content);
    mFrameLayout.addView(mHeader);

    // Content overlay view always shows at the top of content.
    if ((mContentOverlay = onCreateContentOverlayView(inflater, mFrameLayout)) != null) {
        mFrameLayout.addView(mContentOverlay, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
    }

    // Post initial scroll
    mFrameLayout.post(new Runnable() {
        @Override
        public void run() {
            scrollHeaderTo(0, true);
        }
    });

    return mFrameLayout;
}

From source file:org.anurag.fragments.FileGallery.java

/**
 * this function sets transition effect for list view.... 
 * @param list2//from   ww  w  .j  a v  a  2s.  co  m
 */
private void setAnim(ListView list2) {
    // TODO Auto-generated method stub
    list_anim_helper.setTransitionEffect(Constants.LIST_ANIM);
    list2.setOnScrollListener(list_anim_helper);
}

From source file:com.achep.header2actionbar.HeaderFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Activity activity = getActivity();
    assert activity != null;
    mFrameLayout = new FrameLayout(activity);

    mHeader = onCreateHeaderView(inflater, mFrameLayout);
    mHeaderHeader = mHeader.findViewById(android.R.id.title);
    mHeaderBackground = mHeader.findViewById(android.R.id.background);
    assert mHeader.getLayoutParams() != null;
    mHeaderHeight = mHeader.getLayoutParams().height;

    mFakeHeader = new Space(activity);
    mFakeHeader.setLayoutParams(new ListView.LayoutParams(0, mHeaderHeight));

    View content = onCreateContentView(inflater, mFrameLayout);
    if (content instanceof ListView) {
        isListViewEmpty = true;// w ww  .j  av  a  2 s . co  m

        final ListView listView = (ListView) content;
        listView.addHeaderView(mFakeHeader);
        onSetAdapter();
        listView.setOnScrollListener(new AbsListView.OnScrollListener() {

            @Override
            public void onScrollStateChanged(AbsListView absListView, int scrollState) {
                if (mOnScrollListener != null) {
                    mOnScrollListener.onScrollStateChanged(absListView, scrollState);
                }
            }

            @Override
            public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount,
                    int totalItemCount) {
                if (mOnScrollListener != null) {
                    mOnScrollListener.onScroll(absListView, firstVisibleItem, visibleItemCount, totalItemCount);
                }

                isListViewEmpty = listView.getAdapter() == null;
                if (isListViewEmpty) {
                    scrollHeaderTo(0);
                } else {
                    final View child = absListView.getChildAt(0);
                    assert child != null;
                    scrollHeaderTo(child == mFakeHeader ? child.getTop() : -mHeaderHeight);
                    //                        Log.v("header height",String.format("mHeaderHeight:%s",mHeaderHeight));
                }
            }
        });
    } else if (content instanceof GridView) {
        isListViewEmpty = true;

        final GridView grid = (GridView) content;
        //isListViewEmpty = grid.getAdapter() == null;
        //            grid.addHeaderView(mFakeHeader);

        // Merge fake header view and content view.
        final LinearLayout view = new LinearLayout(activity);
        view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        view.setOrientation(LinearLayout.VERTICAL);
        view.addView(mFakeHeader);
        view.addView(grid);

        grid.setOnScrollListener(new AbsListView.OnScrollListener() {

            private ListViewScrollTracker mScrollTracker;;

            @Override
            public void onScrollStateChanged(AbsListView absListView, int scrollState) {
                if (mOnScrollListener != null) {
                    mOnScrollListener.onScrollStateChanged(absListView, scrollState);
                }
            }

            public int getGridScrollY(GridView grid) {

                Method privateStringMethod = null;
                Integer scrollOffset = null;
                Integer scrollExtent = null;
                Integer scrollRange = null;
                try {
                    privateStringMethod = GridView.class.getDeclaredMethod("computeVerticalScrollOffset", null);
                    privateStringMethod.setAccessible(true);
                    scrollOffset = (Integer) privateStringMethod.invoke(grid, null);

                    privateStringMethod = GridView.class.getDeclaredMethod("computeVerticalScrollExtent", null);
                    privateStringMethod.setAccessible(true);
                    scrollExtent = (Integer) privateStringMethod.invoke(grid, null);

                    privateStringMethod = GridView.class.getDeclaredMethod("computeVerticalScrollRange", null);
                    privateStringMethod.setAccessible(true);
                    scrollRange = (Integer) privateStringMethod.invoke(grid, null);
                } catch (NoSuchMethodException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IllegalArgumentException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                return scrollRange;//scrollExtent*scrollOffset;  

            }

            @Override
            public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount,
                    int totalItemCount) {
                if (mScrollTracker == null)
                    mScrollTracker = new ListViewScrollTracker(absListView);
                mScrollPosition = mScrollTracker.calculateIncrementalOffset(firstVisibleItem, visibleItemCount);
                Log.v("header", "scrollPosition:" + mScrollPosition);
                if (mOnScrollListener != null) {
                    mOnScrollListener.onScroll(absListView, firstVisibleItem, visibleItemCount, totalItemCount);
                }

                final View child = absListView.getChildAt(0);
                if (child != null) {
                    int gridScrollY = mScrollPosition;//getGridScrollY((GridView) absListView);
                    scrollHeaderTo(-gridScrollY);

                    //change the size of the fake header on scrolling                        
                    int currentHeight = mFakeHeader.getLayoutParams().height;
                    Integer fakeHeaderHeight = (int) (mHeaderHeight - (gridScrollY * 2));
                    mFakeHeader.setLayoutParams(new android.widget.LinearLayout.LayoutParams(
                            mFakeHeader.getWidth(), fakeHeaderHeight));
                    //                  setViewTranslationY(mFrameLayout, -1*(gridScrollY));
                } else
                    scrollHeaderTo(0);
            }
        });
        content = view;
    } else {

        // Merge fake header view and content view.
        final LinearLayout view = new LinearLayout(activity);
        view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        view.setOrientation(LinearLayout.VERTICAL);
        view.addView(mFakeHeader);
        view.addView(content);

        // Put merged content to ScrollView
        final NotifyingScrollView scrollView = new NotifyingScrollView(activity);
        scrollView.addView(view);
        scrollView.setOnScrollChangedListener(new NotifyingScrollView.OnScrollChangedListener() {
            @Override
            public void onScrollChanged(ScrollView who, int l, int t, int oldl, int oldt) {
                scrollHeaderTo(-t);
            }
        });
        content = scrollView;
    }

    mFrameLayout.addView(content);
    mFrameLayout.addView(mHeader);

    // Content overlay view always shows at the top of content.
    if ((mContentOverlay = onCreateContentOverlayView(inflater, mFrameLayout)) != null) {
        mFrameLayout.addView(mContentOverlay, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
    }

    // Post initial scroll
    mFrameLayout.post(new Runnable() {
        @Override
        public void run() {
            scrollHeaderTo(0, true);
        }
    });

    return mFrameLayout;
}

From source file:in.yangxu.navigationdrawer.view.SuperAwesomeCardFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.homelistviewlayout, container, false);
    final SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout) v
            .findViewById(R.id.activity_main_swipe_refresh_layout);

    if (position == 0) {
        mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override//from ww w . j  a  va  2  s.  c om
            public void onRefresh() {
                mSwipeRefreshLayout.setRefreshing(false);

            }
        });
        ListView listView = (ListView) v.findViewById(R.id.activity_main_listview);
        listView.setCacheColorHint(Color.TRANSPARENT);
        listView.setDividerHeight(0);

        Item item1 = new Item();
        Item item2 = new Item();
        Item item3 = new Item();
        list.add(item1);
        list.add(item2);
        list.add(item3);
        adapter = new ItemAdapter(list, getActivity());
        listView.setAdapter(adapter);

        listView.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {
                if (lastVisibleItem == totalItemCount1 && scrollState == SCROLL_STATE_IDLE) {

                    Item item4 = new Item();
                    list.add(item4);

                    adapter.notifyDataSetChanged();
                }
            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
                    int totalItemCount) {
                lastVisibleItem = firstVisibleItem + visibleItemCount;
                totalItemCount1 = totalItemCount;
            }
        });
    } else {
        mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                mSwipeRefreshLayout.setRefreshing(false);

            }
        });
        ListView listView = (ListView) v.findViewById(R.id.activity_main_listview);
        listView.setCacheColorHint(Color.TRANSPARENT);
        listView.setDividerHeight(0);

        Item item1 = new Item();
        list.add(item1);
        adapter = new ItemAdapter(list, getActivity());
        listView.setAdapter(adapter);

        listView.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {
                if (lastVisibleItem == totalItemCount1 && scrollState == SCROLL_STATE_IDLE) {

                    Item item4 = new Item();
                    list.add(item4);

                    adapter.notifyDataSetChanged();
                }
            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
                    int totalItemCount) {
                lastVisibleItem = firstVisibleItem + visibleItemCount;
                totalItemCount1 = totalItemCount;
            }
        });
    }

    return v;
}

From source file:edu.stanford.mobisocial.dungbeetle.ui.fragments.FeedViewFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    mStatusText = (EditText) view.findViewById(R.id.status_text);
    mStatusText.setOnEditorActionListener(FeedViewFragment.this);
    mStatusText.addTextChangedListener(FeedViewFragment.this);

    mSendTextButton = (ImageView) view.findViewById(R.id.send_text);
    mSendTextButton.setVisibility(View.GONE);
    mSendTextButton.setOnClickListener(mSendStatus);

    mSendObjectButton = (ImageView) view.findViewById(R.id.more);
    mSendObjectButton.setOnClickListener(mSendObject);

    ListView lv = getListView();
    lv.setFastScrollEnabled(true);/* w w w. j a  v  a2s  .  c o  m*/
    lv.setOnItemClickListener(mItemClickListener);
    lv.setOnItemLongClickListener(mItemLongClickListener);
    lv.setOnScrollListener(this);
    lv.setFocusable(true);

    MusubiBaseActivity.getInstance().setOnKeyListener(this);
    // int color = Feed.colorFor(feedName, Feed.BACKGROUND_ALPHA);
    // getListView().setCacheColorHint(color);

    // Sets the unread count to 0 and marks this feed
    // as being displayed on screen.
    // Do this before setCurrentFeed to avoid a requery.
    // TODO: Consider moving outside of fragment.
    App.instance().setCurrentFeed(mFeedUri);
}

From source file:edu.stanford.mobisocial.dungbeetle.ui.fragments.AppsViewFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    ListView lv = getListView();
    lv.setFastScrollEnabled(true);/*from w  w  w.  ja  v a  2s.  c  o  m*/
    lv.setOnItemClickListener(mItemClickListener);
    lv.setOnItemLongClickListener(mItemLongClickListener);
    lv.setOnScrollListener(this);
    lv.setFocusable(true);

    MusubiBaseActivity.getInstance().setOnKeyListener(this);
    // int color = Feed.colorFor(feedName, Feed.BACKGROUND_ALPHA);
    // getListView().setCacheColorHint(color);
}

From source file:ca.zadrox.dota2esportticker.ui.BaseActivity.java

protected void enableActionBarAutoHide(final ListView listView) {
    initActionBarAutoHide();/*from  w  ww. j  av  a  2  s .c om*/
    listView.setOnScrollListener(new AbsListView.OnScrollListener() {
        final static int ITEMS_THRESHOLD = 3;
        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:com.maxleapmobile.gitmaster.ui.fragment.UserFragment.java

private void initUI(View view) {
    mProgressBar = (ProgressBar) view.findViewById(R.id.search_progress);
    mProgressBar.setVisibility(View.GONE);

    ListView listView = (ListView) view.findViewById(R.id.search_list);
    if (mUsers == null) {
        mUsers = new ArrayList<>();
    }/*  www . j av  a 2s.co m*/
    if (mFlag == FLAG_USER_FOLLOWING
            && mUsername.equals(PreferenceUtil.getString(mContext, Const.USERNAME, null))) {
        mUserAdapter = new UserAdapter(mContext, mUsers, true);
    } else {
        mUserAdapter = new UserAdapter(mContext, mUsers, false);
    }
    listView.setOnScrollListener(this);
    listView.setAdapter(mUserAdapter);
    listView.setEmptyView(view.findViewById(R.id.search_empty));

    if (mFlag == FLAG_USER_FOLLOWING) {
        fetchFollowingData(1);
    } else if (mFlag == FLAG_USER_FOLLOWER) {
        fetchFollowerData(1);
    } else if (mFlag == FLAG_ORG) {
        fetchOrgData();
    }
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent intent = new Intent(mContext, UserInfoActivity.class);
            intent.putExtra(Const.USERNAME, mUsers.get(position).getLogin());
            mContext.startActivity(intent);
        }
    });
}