All the Android experts,
I'm working on Android TV app. I face problem on Dpad navigation. i would like to stop auto Dpad navigate while KeyDown UP and DOWN.
i wrote a listener on a focusable TextView, if TextView on key UP then scroll UP the listview, and key DOWN scroll DOWN.
but the below code seen failed to scroll my listview, my focus move to other focus point while i press DOWN.
Is there any solution that i can override the auto focus navigation? i would like my TextView ignore the auto navigation to next focus while i press key UP and DOWN.
Thank you.
textView.setOnKeyListener(new View.OnKeyListener(){
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
switch(keyCode) {
case KeyEvent.KEYCODE_DPAD_UP:
case KeyEvent.KEYCODE_PAGE_UP:
listview_scrollUP();
break;
case KeyEvent.KEYCODE_DPAD_DOWN:
case KeyEvent.KEYCODE_PAGE_DOWN:
listview_scrollDOWN();
break;
}
}
return false;
}
});
After some research, i got some idea to solve my problem.
i used setDescendantFocusability() block the rest of my fragments(viewgroup) while my dpad focus enter the targeted fragment, ideally is to space out the key UP and DOWN for my purpose usage (without processing dpad navigate next focus).
textview.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
LinearLayout menu = (LinearLayout)getActivity().findViewById(R.id.mainMenuLayout);
menu.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
}
}
});
my targeted fragment just needed LEFT and RIGHT to let dpad change to next focus, and then my UP and DOWN onKey Down is used for scrolling the listview.
setDescendantFocusability() enable while the dpad navigate focus reached the edge of my fragment focusing point.
textview.setOnKeyListener(new View.OnKeyListener(){
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
switch(keyCode) {
case KeyEvent.KEYCODE_DPAD_LEFT:
LinearLayout menu = (LinearLayout)getActivity().findViewById(R.id.mainMenuLayout);
menu.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
menuItem1.requestFocus();
break;
case KeyEvent.KEYCODE_DPAD_UP:
case KeyEvent.KEYCODE_PAGE_UP:
listview_scrollUP();
break;
case KeyEvent.KEYCODE_DPAD_DOWN:
case KeyEvent.KEYCODE_PAGE_DOWN:
listview_scrollDOWN();
break;
}
}
return false;
}
});
this is what i came out of to solve my problem.
wish this info help up other.
thank you.