나는 결국 함께 왔어요 솔루션입니다 : 즉 조각에 대한
추가 사용자 라이프 사이클 리스너 : onFragmentResume 내가 보여줄 필요가 때 수동으로 전화 onFragmentPause 이벤트/조각을 숨기거나 전환합니다.
@Override
public void onFragmentResume() {
//Enable focus
if (getView() != null) {
//Enable focus
setEnableView((ViewGroup) view, true);
//Clear focusable elements
focusableViews.clear();
}
//Restore previous focus
if (previousFocus != null) {
previousFocus.requestFocus();
}
}
@Override
public void onFragmentPause() {
//Disable focus and store previously focused
if (getView() != null) {
//Store last focused element
previousFocus = getView().findFocus();
//Clear current focus
getView().clearFocus();
//Disable focus
setEnableView((ViewGroup) view, false);
}
}
/**
* Find focusable elements in view hierarchy
*
* @param viewGroup view
*/
private void findFocusableViews(ViewGroup viewGroup) {
int childCount = viewGroup.getChildCount();
for (int i = 0; i < childCount; i++) {
View view = viewGroup.getChildAt(i);
if (view.isFocusable()) {
if (!focusableViews.contains(view)) {
focusableViews.add(view);
}
}
if (view instanceof ViewGroup) {
findFocusableViews((ViewGroup) view);
}
}
}
/**
* Enable view
*
* @param viewGroup
* @param isEnabled
*/
private void setEnableView(ViewGroup viewGroup, boolean isEnabled) {
//Find focusable elements
findFocusableViews(viewGroup);
for (View view : focusableViews) {
view.setEnabled(isEnabled);
view.setFocusable(isEnabled);
}
}
setonclicklistner를 프로그래밍 방식으로 onCreate에 추가 할 수 있습니다. –
이런 식으로. https://stackoverflow.com/a/25841415/3364266 –
왜 onClickListener인가? onFocusChanged 같은 것이 필요합니까? 터치 이벤트를 사용하지 마십시오. 리모콘이있는 Android TV입니다. – Veljko