Skip to content

Instantly share code, notes, and snippets.

@Aldo-f
Created April 6, 2017 11:36
Show Gist options
  • Save Aldo-f/1c57ff525c0b05289b95140d713dbf8f to your computer and use it in GitHub Desktop.
Save Aldo-f/1c57ff525c0b05289b95140d713dbf8f to your computer and use it in GitHub Desktop.
Enter name to continue
/*
* OnClickListener will store the name as entered in the EditText view, in a String,
* then it will send the string to the next Activity for further use.
*
* Player won't proceed without entering a name;
* */
namesField.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
playerNames = namesField.getText().toString();
if (playerNames.equals("")) {
Toast msg = Toast.makeText(getApplicationContext(), "Enter a name.", Toast.LENGTH_SHORT);
msg.show();
} else if (!(playerNames.equals(""))) {
Intent proceedToMain = new Intent(getApplicationContext(), MainActivity.class);
proceedToMain.putExtra("playerNames", playerNames);
startActivity(proceedToMain);
finish();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment