Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save enrichman/d622e9cce53aec1d2f217accd00a6998 to your computer and use it in GitHub Desktop.
Save enrichman/d622e9cce53aec1d2f217accd00a6998 to your computer and use it in GitHub Desktop.
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