Created
September 29, 2016 15:29
-
-
Save pantos27/c34b3af67654f28d9aa334a0291a3004 to your computer and use it in GitHub Desktop.
Custom Android ViewPager for disabling scrolling with navigation buttons (left/right)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
viewPager = new ViewPager(this){ | |
@Override | |
public boolean dispatchKeyEvent(KeyEvent event) { | |
View nextFocus = findFocus(); | |
if(event.getAction() == KeyEvent.ACTION_DOWN) { | |
if(event.getKeyCode() == KeyEvent.KEYCODE_DPAD_RIGHT) | |
Log.d("TestFocus", "" + (nextFocus = FocusFinder.getInstance().findNextFocus(this, findFocus(), FOCUS_RIGHT))); | |
else if(event.getKeyCode() == KeyEvent.KEYCODE_DPAD_LEFT) | |
Log.d("TestFocus", "" + (nextFocus = FocusFinder.getInstance().findNextFocus(this, findFocus(), FOCUS_LEFT))); | |
if(nextFocus == null) | |
return true; | |
} | |
return super.dispatchKeyEvent(event); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment