The below is the piece of code that i have written for transferring the focus from one edit text to another, but the problem that i got with this implementation is, the focus moves to the particular edit text, and suddenly moves to the next edit text.So, i could not able to enter anything , since the focus is not at all staying that particular edit text ..
//some code comes here // gun_pistolNotes and gun_pistolModel are two diff. editText ...... ...... gun_pistolNotes.setOnEditorActionListener(new OnEditorActionListener(){ @Override public boolean onEditorAction(TextView view,int actionId, KeyEvent event){ if(actionId == EditorInfo.IME_ACTION_UNSPECIFIED){ gun_pistolModel.requestFocus(); // moves to this edittext and suddenly moves to another editext return true; } return false; } }); ...... ...... //some code comes here
Any Help is Appreciated.
Thanks in advance.
Best Answer
I realise this is an old question, but I was facing a similar issue & after hours of frustration, I found the problem, so just thought I should post it here in case someone else needs it.
In my code I realised that for some reason specifying
android:inputype
on my edittext was causing this "jumping" behaviour. So if I haveEditText1
withandroid:inputType="textCapSentences"
in the XML, callingrequestFocus()
onEditText1
causes it to get highlighted briefly before moving focus onto the next view.I am not sure if this is a bug within Android or if it is indeed something else that I am missing. I tried setting
inputType
programmatically & within various points in my code, withsetInputType()
but it did not work for me. So for now I have just removed theinputType
attribute &requestFocus()
works as it should.