私は最後に作ってみた解決策は以下のとおりです。すなわち、フラグメントのための
追加カスタムライフサイクルのリスナー: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