Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.restoalan;
- import androidx.appcompat.app.AppCompatActivity;
- import android.content.Context;
- import android.content.Intent;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.Toast;
- public class LoginActivity extends AppCompatActivity {
- DatabaseHelper db;
- Button login, register;
- EditText username, password;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_login);
- db = new DatabaseHelper(this);
- username = (EditText)findViewById(R.id.edtText_username);
- password = (EditText)findViewById(R.id.edtText_password);
- login = (Button)findViewById(R.id.btn_login);
- register = (Button)findViewById(R.id.btn_register);
- //register
- register.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Intent registerIntent = new Intent(LoginActivity.this, RegistrasiActivity.class);
- startActivity(registerIntent);
- finish();
- }
- });
- //login
- login.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- String strUsername = username.getText().toString();
- String strPassword = password.getText().toString();
- Boolean masuk = db.checkLogin(strUsername, strPassword);
- if (masuk == true) {
- Boolean updateSession = db.upgradeSession("ada", 1);
- if (updateSession == true) {
- Toast.makeText(getApplicationContext(), "Berhasil Masuk", Toast.LENGTH_SHORT).show();
- Intent mainIntent = new Intent(LoginActivity.this, lisviewActivity.class);
- startActivity(mainIntent);
- finish();
- }
- }
- else {
- Toast.makeText(getApplicationContext(), "Masuk Gagal", Toast.LENGTH_SHORT).show();
- }
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment