Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Custom Android ViewPager for disabling scrolling with navigation buttons (left/right)
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