2
I am 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"
/>
would like to jump to the next field automatically when the user puts a character in the field in which it is.
tried to use the attribute android:nextFocus
but he asks the enter to jump to another field.
It follows below 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) {
}
});
}
}
I thank you for your help ! hugs
You have to initialize the attributes
letra1_1
andletra1_2
, in theonCreate()
, using the methodfindViewById()
– ramaral
Thank you very much ! now it worked ! hugs
– Linkon Louvison