I've some settings page in my app. Once the activity gets starts directly it focus to edittext and i used following code to clear foucs.
<RelativeLayout
android:id="@+id/RequestFocusLayout"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="0px"
android:layout_height="0px"/>
and in java code
RelativeLayout focuslayout = (RelativeLayout) findViewById(R.id.RequestFocusLayout);
focuslayout.requestFocus();
The above code is working fine when activity starts at first time and if same activity starts again, automatically edittext get focus.
Can anyone help me to solve this issue.
Actually, the first focusable view in the activity receives initial focus. If that happens to be your EditText
, it will be initially focused.
If you don't want that, here's your options:
Programmatically identify what view you do want to give initial focus to.
@Override
protected void onStart() {
super.onStart();
findViewById( R.id.yourOtherViewId ).requestFocus();
}
If you rather it appears as though "no view has initial focus" you could make the parent view group focusable. In the following example, I make my LinearLayout
focusable by setting android:focusableInTouchMode="true"
:
<LinearLayout
android:focusableInTouchMode="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
...
If Come back from other activity edittext get focused.
put these line onStart() or on onReusme()
RelativeLayout focuslayout = (RelativeLayout) findViewById(R.id.RequestFocusLayout);
focuslayout.requestFocus();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With