0

When I'm writing in an EditText, if I push the next/done key then the focus will move to the next EditText. How to forbid this behaviour (programmatically)?

suvojit_007
  • 1,690
  • 2
  • 17
  • 23
zeus
  • 12,173
  • 9
  • 63
  • 184
  • can try to add android:focusableInTouchMode="true" – PJain Jun 20 '19 at 13:37
  • @PJain : this is already set to true :( – zeus Jun 20 '19 at 13:54
  • Try this [setOnEditorActionListener](https://stackoverflow.com/a/10619174/3816129) – Dmytro Batyuk Jun 20 '19 at 14:37
  • @DmytroBatyuk yes I already tried but the problem i have is that it's from OnEditorActionListener that i want to move the focus and i it's when i do theOtherEditText.requestfocus from OnEditorActionListener that everything go wrong and the focus jump to another edittext – zeus Jun 20 '19 at 14:48

2 Answers2

0

Just setFocusable(true) to the mother view of your edittext

Turvy
  • 882
  • 1
  • 8
  • 23
  • no I want to be able to focus the view when I click on it. I don't want to focus the view from the button next/done/none/etc. of the keyboard – zeus Jun 20 '19 at 13:53
  • Did you try my solution at least? if you setFocusable and setFocusableInTouchMode to true to the MOTHER VIEW, you don't prevent from focusabling edittext by click. Maybe you need to setFocusable and setFocusableInTouchMode to each Edittext to false too – Turvy Jun 20 '19 at 14:23
0

You may try this code :

yourEditText.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_NEXT) {
                // do something with next printed on your editText

            }
            return true;
        }
    });

You can manage cases for different option like other action(Done/Next/Search etc.) too.