Created
March 22, 2017 23:50
-
-
Save enrichman/d622e9cce53aec1d2f217accd00a6998 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package it.enricocandino.loginviewexample; | |
import android.content.Context; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.EditText; | |
import android.widget.Toast; | |
public class MainActivity extends AppCompatActivity { | |
private Context mContext = MainActivity.this; | |
private EditText usernameEditText; | |
private EditText passwordEditText; | |
private Button loginButton; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
usernameEditText = (EditText) findViewById(R.id.username_edittext); | |
passwordEditText = (EditText) findViewById(R.id.password_edittext); | |
loginButton = (Button) findViewById(R.id.login_button); | |
loginButton.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
String username = usernameEditText.getText().toString(); | |
String password = passwordEditText.getText().toString(); | |
if (!username.equals("") && !password.equals("")) { | |
Toast.makeText(mContext, "Logging in", Toast.LENGTH_SHORT).show(); | |
} else { | |
Toast.makeText(mContext, "Missing username or password", Toast.LENGTH_SHORT).show(); | |
} | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment