views:

133

answers:

1

I have a TextView with android:maxLength set to 3 and another with android:maxLength set to 7. I want focus to automatically move to the second TextView once the 3 chars of the first TextView are filled up. Is this possible without inheriting TextView and writing a custom implementation ?

+1  A: 

I haven't tried but this might work.

Setup a listener to fire when the text was changed, for this use

addTextChangedListener(TextWatcher watcher)

Then based on the text length you can request the focus change to the next field.

If you want to find out the next field you can call View.focusSearch(View.FOCUS_FORWARD) Find the nearest view in the specified direction that can take focus. This does not actually give focus to that view.

Pentium10
I did this - public void onTextChanged(CharSequence s, int start, int before, int count) { if (s.length() == 3) { Log.d(TAG,"Next focus is at: "+tv1.getNextFocusDownId()); tv1.requestFocus(View.FOCUS_DOWN); }But it did not work - what am I doing wrong ?The Log prints the message correctly when length is 3, but the focus does not shift automatically to the next view.
Naseer
Please ignore my previous comment - tv2.requestFocus() worked.Thanks !
Naseer