1
I created a "register" screen where the user informs the name/nickname and where there is a Continue button that goes to another screen. I would like this new screen to open when the user presses the Enter key, but I do not know how to do for the Enter key to have this function.
Below the code of the home screen
public class CadastroActivity extends AppCompatActivity {
EditText edtNome;
Button btnContinuar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cadastro);
edtNome = (EditText) findViewById(R.id.edtNome);
btnContinuar = (Button) findViewById(R.id.btnContinuar);
btnContinuar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent EnviarDados = new Intent(CadastroActivity.this, ResultadoActivity.class);
String txtNome = edtNome.getText().toString();
Bundle bundle = new Bundle();
bundle.putString("nome", txtNome);
EnviarDados.putExtras(bundle);
startActivity(EnviarDados);
}
});
}
}
That would be my suggestion. I would not be able to go so deep for technical difficulties of my own, not to have deepened in Android, but by the rumor theory suggest it. And important detail: in this answer, implicitly the action of calling the other activity was encapsulated in a method. So this call can be leveraged to be used by the button as well
– Jefferson Quesado
Yes, as a way of learning I put the explicit Software. But I could have done
editText.setOnEditorActionListener(this)
, Extend the Activity interfaceOnEditorActionListener
and make a field check to be validated withv.equals(editText)
.– Marcos Rocha