I'm doing a crossword and each field is an EditText as in the example below:
// GRIDLAYOUT USADO PARA ORGANIZAR OS EDIT TEXT EM UMA MATRIZ
<GridLayout
android:layout_width="match_parent"
android:layout_height="382dp"
android:layout_weight="0.26">
<EditText
android:layout_width="30dp"
android:layout_height="30dp"
android:gravity="center"
android:id="@+id/letra1_1"
android:inputType="textCapSentences"
android:maxLength="1"
android:singleLine="true"
android:textSize="25dp"
android:background="@drawable/square_semborda"
android:layout_row="1"
android:layout_column="1"
/>
<EditText
android:layout_width="30dp"
android:layout_height="30dp"
android:gravity="center"
android:id="@+id/letra1_2"
android:inputType="textCapSentences"
android:maxLength="1"
android:singleLine="true"
android:textSize="25dp"
android:background="@drawable/square_semborda"
android:layout_row="1"
android:layout_column="2"
/>
I would like to jump to the next field automatically when the user places a character in the field it is in.
I tried to use the android:nextFocus
attribute but it asks enter to jump to another field.
The following is the java code as it was ... but the app stops working when I access the screen of this activity
package com.example.android.cruzadinhas_eic;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
public class LeptospiroseActivity extends AppCompatActivity {
public EditText letra1_1;
public EditText letra1_2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_leptospirose);
letra1_1.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
letra1_2.requestFocus();
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
});
}
}
Thank you for your help! hugs