ListView - Fast scrollbar that doesn't appear for the first time in 4.4 Kitkat

I have one list view with fast scrolling enabled. For the first time, the quick scroll bar is not visible. But if I go to another screen and get back to it, then it will become visible. This issue is observed with the latest version of Android OS. those. on 4.4 - Kitkat

First view

enter image description here

Second visit

enter image description here

Any idea on why this is happening like this?

+4
source share
3 answers

I have the same problem. I am using the solution:

gridView.setFastScrollEnabled(true);

if (Build.VERSION.SDK_INT >= 19) {
    gridView.setOnScrollListener(new OnScrollListener() {
        private static final int DELAY = 2000;
        private AbsListView view;

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            if (scrollState != SCROLL_STATE_IDLE) {
                view.setFastScrollAlwaysVisible(true);
                handler.removeCallbacks(runnable);
            }
            else {
                this.view = view;
                handler.postDelayed(runnable, DELAY);
            }
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
        }

        private Handler handler = new Handler();
        private Runnable runnable = new Runnable() {
        @Override
        public void run() {
            view.setFastScrollAlwaysVisible(false);
            view = null;
        }
        };
    });
}
+6
source

What worked for me was to defer the call setFastScrollEnabled().

if (Build.VERSION.SDK_INT >= 19) {
  mListView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
    @SuppressWarnings("deprecation")
    @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
    @Override
    public void onGlobalLayout() {
      mListView.setFastScrollEnabled(true);
      if (Build.VERSION.SDK_INT >= 16) {
        mListView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
      } else {
        mListView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
      }
    }
  });
} else {
  mListView.setFastScrollEnabled(true);
}
0
source

( ).

:

  public static void setFastScrolledEnabled(final AdapterView<?> adapterView,final boolean enable)
    {
    final GridView gridView;
    final ListView listView;
    if(adapterView instanceof GridView)
      {
      gridView=(GridView)adapterView;
      listView=null;
      }
    else if(adapterView instanceof ListView)
      {
      listView=(ListView)adapterView;
      gridView=null;
      }
    else throw new UnsupportedOperationException("setFastScrolledEnabled is only available for gridView/listView");
    if(Build.VERSION.SDK_INT==VERSION_CODES.KITKAT)
      adapterView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener()
        {
          @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
          @Override
          public void onGlobalLayout()
            {
            if(gridView!=null)
              gridView.setFastScrollEnabled(enable);
            else if(listView!=null)
              listView.setFastScrollEnabled(enable);
            adapterView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }
        });
    else if(gridView!=null)
      gridView.setFastScrollEnabled(enable);
    else if(listView!=null)
      listView.setFastScrollEnabled(enable);
    }
0
source

All Articles