Hey guys pretty new to android studio, like the title says I've tried to put the text within the EditText into a var called "username" which I want to be able to use within my inner class but I don't know how to make it accessible from within.
here's what I do with the EditText, within the onCreate: (KeyListener is the name of my inner class)
KeyListener KL_Instance = new KeyListener();
EditText input_text = (EditText) findViewById(R.id.inputText);
input_text.setOnKeyListener(KL_Instance);
String username = input_text.getText().toString();
And here's what i'm trying to do within the inner class:
public class KeyListener implements View.OnKeyListener
{
@Override
public boolean onKey(View view, int keyCode, KeyEvent keyEvent)
{
if (keyCode == KeyEvent.KEYCODE_AT)
{
Toast.makeText(MainActivity.this, "Do not type @", Toast.LENGTH_LONG).show();
}
//if the enter key is pressed, then check to see if username is 8 or more chars
if (keyCode == keyEvent.KEYCODE_ENTER)
{
//if it is, display it
if(username.length => 8)
{
Toast.makeText(MainActivity.this, "Hi, " + username, Toast.LENGTH_LONG).show();
}else //else, ask for a username of atleast 8 chars
{
Toast.makeText(MainActivity.this, "Please enter a username that is 8 or more chars", Toast.LENGTH_LONG).show();
}
}
return false;
}
}
But it says "cannot resolve symbol 'username'" and I cant access "input_text" within that class either so If someone could help me out here it would be greatly appreciated, Thanks in advance :)