[Android] Scroll to top on current tab click

Geoffrey Métais git at videolan.org
Wed Jan 27 15:52:32 CET 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Jan 27 15:51:52 2016 +0100| [2ab56d3cc856def7735343e00030ad0b447de3ce] | committer: Geoffrey Métais

Scroll to top on current tab click

> https://code.videolan.org/videolan/vlc-android/commit/2ab56d3cc856def7735343e00030ad0b447de3ce
---

 .../videolan/vlc/gui/audio/AudioBrowserFragment.java | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
index a8ad6ac..0c403aa 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -160,6 +160,7 @@ public class AudioBrowserFragment extends MediaBrowserFragment implements SwipeR
         mTabLayout = (TabLayout) v.findViewById(R.id.sliding_tabs);
         mTabLayout.setupWithViewPager(mViewPager);
 
+        setTabsClickListeners();
         mViewPager.addOnPageChangeListener(this);
 
         songsList.setOnItemClickListener(songListener);
@@ -203,6 +204,25 @@ public class AudioBrowserFragment extends MediaBrowserFragment implements SwipeR
         return v;
     }
 
+    private void setTabsClickListeners() {
+        for (int i = 0; i < mTabLayout.getTabCount(); ++i){
+            final int position = i;
+            ((ViewGroup)mTabLayout.getChildAt(0)).getChildAt(i).setOnClickListener(new View.OnClickListener() {
+                @Override
+                public void onClick(View v) {
+                    if(position == mViewPager.getCurrentItem()){
+                        ((ListView)mLists.get(position)).smoothScrollToPosition(0);
+                    } else {
+                        mViewPager.setCurrentItem(position);
+                        updateEmptyView(position);
+                        setFabPlayShuffleAllVisibility();
+                        tcl.onPageSelected(position);
+                    }
+                }
+            });
+        }
+    }
+
     AbsListView.OnScrollListener mScrollListener = new AbsListView.OnScrollListener(){
         @Override
         public void onScrollStateChanged(AbsListView view, int scrollState) {



More information about the Android mailing list