I have a couple of edit text boxes on a single line. After the user types in a specific number of characters in the first I want to automatically move to the next edit text. How do I achieve this?
android:imeOptions="actionSend" /> You can then listen for presses on the action button by defining a TextView.OnEditorActionListener for the EditText element. In your listener, respond to the appropriate IME action ID defined in the EditorInfo class, such as IME_ACTION_SEND . For example: findViewById<EditText>(R.
First, you can simply have it so that if the EditText block is empty, it is immediately repopulated with a "/" char. Alternatively, make it so that if the previous char is / , then prevent the user from deleting back.
You can use the attribute style="@style/your_style" that is defined for any widget. The attribute parent="@android:style/Widget. EditText" is important because it will ensure that the style being defined extends the basic Android EditText style, thus only properties different from the default style need to be defined.
You can achieve this by using the Text Watcher
class and then set the focus on the next EditText
in the OnTextChanged()
method of the TextWatcher.
In your case, since you have two Edit Texts, say et1
and et2
. You can try out the following code:-
et1.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start,int before, int count)
{
// TODO Auto-generated method stub
if(et1.getText().toString().length()==size) //size as per your requirement
{
et2.requestFocus();
}
}
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
// TODO Auto-generated method stub
}
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
I have not checked out the code myself, but I hope this will help you solve your problem.
There is a simpler way to do this which doesn't involve knowledge of the ids of the EditText views. For use with android:maxLength="1".
// onTextChanged
@Override
public void onTextChanged(CharSequence s, int start, int before, int count)
{
TextView text = (TextView)getCurrentFocus();
if (text != null && text.length() > 0)
{
View next = text.focusSearch(View.FOCUS_RIGHT); // or FOCUS_FORWARD
if (next != null)
next.requestFocus();
doSearch(); // Or whatever
}
}
// afterTextChanged
@Override
public void afterTextChanged(Editable s) {}
// beforeTextChanged
@Override
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {}
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