My first android project! I have a Login Activity. Within it there are two EditText
fields, "username" and "password". I've made a listener for when the user has completed the field, namely an onEditorActionListener
. My motivation behind this is that I need the username and password fields as a String Variable to send to Volley and onto an API. The password Listener is nearly identical to the code below.
final EditText loginEditText_User = (EditText) findViewById(R.id.login_user);
loginEditText_User.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_NEXT){
// TODO Retrieve Username here
Log.d("[userName]", loginEditText_User.getText().toString());
loginEditText_Pass.requestFocus();
}
return true;
}
});
I've tried simply declaring a variable String userName
before the listener and setting the value within the block via userName = loginEditText_User.getText().toString();
, but this doesn't work because "the variable 'userName' is accessed from within inner class, needs to be declared final". However, but when declared final
, I obviously "cannot assign value to final variable".
I've seen related questions such as this and this, but they're not quite the same thing.
Thanks in advance!