0

I have two EditTexts. EditText1 and EditText2

I also have a feature that hides EditText2 depending on which option you choose.

The problem is that if you are focusing on EditText2 and run setVisibility(View.GONE) on it then it automatically reverts focus back to EditText1 which does other stuff.

How can I prevent any focus events and just keep everything the same?

I've tried

EditText2.setFocusableInTouchMode(true);
EditText2.setFocusable(true);
EditText2.setFocusableInTouchMode(false);
EditText2.setFocusable(false);

While they disable focus on EditText2 As soon as visibility is set to gone, EditText1 receives focus

Trevor Wood
  • 2,347
  • 5
  • 31
  • 56

1 Answers1

1

This solved my problem. Stop EditText from gaining focus at Activity startup

Putting this right before my EditText

<LinearLayout
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:layout_width="0px"
        android:layout_height="0px"/>
Trevor Wood
  • 2,347
  • 5
  • 31
  • 56