В xml у editText
есть эти 2 атрибута:
android:focusable="true"
android:focusableInTouchMode="true"
Пытался установить фокус с помощью такого кода:
synchronized (getContext()) {
editText.requestFocus();
((InputMethodManager) cntxt.getSystemService(INPUT_METHOD_SERVICE))
.showSoftInput(editText, SHOW_IMPLICIT);
}
Не работает.
UPD:
Подробнее.
В Navigation Drawer-е нажимаю кнопку, он закрывается, дальше во фрагменте (вкладки) пытаюсь установить фокус.
Никакие задержки не помогли.
editText.requestFocus()
возвращает true
.
Добавил к View
, на который хочу установить фокус, OnFocusChangeListener
.
Сначала hasFocus
равен true
, а потом false
.
Thread Dupm при hasFocus==false
:
java.lang.Thread.State: RUNNABLE
at ru.obrazcenter.Utils$1MyFocusListener.onFocusChange(MyUtils.java:19)
at android.view.View.onFocusChanged(View.java:4836)
at android.widget.TextView.onFocusChanged(TextView.java:7641)
at android.view.View.clearFocusInternal(View.java:4728)
at android.view.View.unFocus(View.java:4762)
at android.view.ViewGroup.unFocus(ViewGroup.java:822)
at android.view.ViewGroup.unFocus(ViewGroup.java:822)
at android.view.ViewGroup.unFocus(ViewGroup.java:822)
at android.view.ViewGroup.requestChildFocus(ViewGroup.java:624)
at android.view.ViewGroup.requestChildFocus(ViewGroup.java:630)
at android.widget.ScrollView.requestChildFocus(ScrollView.java:1397)
at android.view.ViewGroup.requestChildFocus(ViewGroup.java:630)
at android.view.View.handleFocusGainInternal(View.java:4610)
at android.view.ViewGroup.handleFocusGainInternal(ViewGroup.java:604)
at android.view.View.requestFocusNoSearch(View.java:6999)
at android.view.View.requestFocus(View.java:6978)
at android.view.ViewGroup.requestFocus(ViewGroup.java:2369)
at android.widget.ScrollView.onRequestFocusInDescendants(ScrollView.java:1433)
at android.view.ViewGroup.requestFocus(ViewGroup.java:2373)
at android.view.View.requestFocus(View.java:6945)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1296)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1116)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1642)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:714)
at android.support.design.widget.HeaderScrollingViewBehavior.onMeasureChild(HeaderScrollingViewBehavior.java:90)
at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onMeasureChild(AppBarLayout.java:1391)
at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:784)
at android.view.View.measure(View.java:16497)
at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:1081)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291)
at android.view.View.measure(View.java:16497)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1912)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1109)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1291)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:996)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5600)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
at android.view.Choreographer.doCallbacks(Choreographer.java:574)
at android.view.Choreographer.doFrame(Choreographer.java:544)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
requestFocus()
? Возможно слишком рано при создании экрана?