마지막 포커스 뷰 찾기
Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.fragment);
new CurrentFocusView(currentFragment.getView());
또는
View tView = findViewById(R.id.fragment);
new CurrentFocusView(tView);
마지막으로 저장된 포커스 뷰 가져오기
CurrentFocusView.mFocusView 또는 new CurrentFocusView().getFocusView();
=================== 현재 포커스 찾아서 focus view 저장하는 클래스 생성 ============
public class CurrentFocusView {
private final String TAG = IKeyEvent.TAG + this.getClass().getSimpleName();
private View mRootView;
public static View mFocusView;
public CurrentFocusView() {
}
public CurrentFocusView(View view) {
mRootView = view;
findFocusView(mRootView);
android.util.Log.d(TAG, "CurrentFocusView: getFocusView()="+getFocusView());
}
public View getFocusView() {
return mFocusView;
}
public void setFocusView(View focusView) {
mFocusView = focusView;
}
public synchronized void findFocusView(View view) {
if (view.hasFocus() == true) {
android.util.Log.d(TAG, "findFocusView: hasFocusView="+view);
setFocusView(view);
}
if (view instanceof ViewGroup) {
ViewGroup vg = (ViewGroup) view;
if (vg.getChildCount() > 0) {
for (int i = 0; i < vg.getChildCount(); i++) {
findFocusView(vg.getChildAt(i));
}
}
}
}
===============================================
댓글 없음:
댓글 쓰기