SHARE
TWEET

Main Activity Java

Umambeeirozst Mar 25th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.example.kedaiumis;
  2.  
  3. import android.content.Intent;
  4. import android.os.Bundle;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.view.View;
  7. import android.widget.EditText;
  8. import android.widget.Toast;
  9.  
  10. public class MainActivity extends AppCompatActivity {
  11.  
  12.     EditText editText1 ,editText2; //Deklarasi object dari class EdiText
  13.     String text1 ,text2; //Deklarasi object string
  14.  
  15.  
  16.     @Override
  17.     protected void onCreate(Bundle savedInstanceState) {
  18.         super.onCreate(savedInstanceState);
  19.         setContentView(R.layout.activity_main);
  20.         getSupportActionBar().setTitle("Kedai Umis");
  21.         getSupportActionBar().setSubtitle("Maryanah 161011400043");
  22.  
  23.     }
  24.  
  25.     public void loginMasuk(View view) {
  26.         //Method onClick pada Button
  27.  
  28.         editText1 = (EditText)findViewById(R.id.edittext_username);
  29.         editText2 = (EditText) findViewById(R.id.edittext_password);
  30.         text1 = editText1.getText().toString();
  31.         text2 = editText2.getText().toString();
  32.  
  33.         //Kondisi jika username dan password benar maka akan menampilkan pesan text toast
  34.         //Login sukses dan masuk ke activity 2
  35.         if ((text1.contains("Username"))&&((text2.contains("Password")))) {
  36.             Toast.makeText(this, "Login Sukses", Toast.LENGTH_SHORT).show();
  37.             Intent intent = new Intent(MainActivity.this, SecondActivity.class);
  38.             startActivity(intent);
  39.         }
  40.  
  41.         else if ((text1.matches("")||text2.matches("")))
  42.           /*
  43.           Atau jika input text 1 dan text 2 kosong
  44.            */
  45.         {
  46.             //Maka akan menampilkan pesan text toast
  47.             Toast.makeText(this, "Isikan Username dan Password", Toast.LENGTH_SHORT).show();
  48.  
  49.         }
  50.  
  51.         else {
  52.             //jika kedua kondisi diatas tidak memenuhi
  53.  
  54.             Toast.makeText(this, "Login Gagal /Username Password Salah", Toast.LENGTH_SHORT).show();
  55.         }
  56.  
  57.     }
  58.  
  59.  
  60. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top