Advertisement
Putra-Kun123

[Update v3] LoginActivity.java

Feb 28th, 2020
8,761
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. package notes.bapakkau;
  2.  
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.database.Cursor;
  6. import android.database.sqlite.SQLiteDatabase;
  7. import android.os.Bundle;
  8. import android.view.View;
  9. import android.widget.Button;
  10. import android.widget.EditText;
  11. import android.widget.Toast;
  12.  
  13. public class LoginActivity extends Activity {
  14. Button login, batal, keluar;
  15. Cursor cursor;
  16. SQLiteDatabase db;
  17. EditText user, pass;
  18. Database sqlite, sqlite2;
  19.  
  20. public void onCreate(Bundle savedInstanceState) {
  21. super.onCreate(savedInstanceState);
  22. setContentView(R.layout.login);
  23. SQLiteDatabase writableDatabase = new Database(this).getWritableDatabase();
  24. sqlite2 = new Database(this);
  25. cursor = sqlite2.getReadableDatabase().rawQuery("Select*from login where status='masuk'", (String[]) null);
  26. cursor.moveToFirst();
  27. if (cursor.getCount() > 0) {
  28. startActivity(new Intent(getBaseContext(), MenuActivity.class));
  29. finish();
  30. }
  31. user = (EditText) findViewById(R.id.edusername);
  32. pass = (EditText) findViewById(R.id.edpassword);
  33. login = (Button) findViewById(R.id.btnlogin);
  34. keluar = (Button) findViewById(R.id.btnkeluar);
  35. batal = (Button) findViewById(R.id.btnbatal);
  36. login.setOnClickListener(new View.OnClickListener() {
  37. public void onClick(View arg0) {
  38. SQLiteDatabase db = sqlite2.getReadableDatabase();
  39. cursor = db.rawQuery("Select*from login where username='" + user.getText().toString() + "' and password='" + pass.getText().toString() + "'", (String[]) null);
  40. cursor.moveToFirst();
  41. if (LoginActivity.this.cursor.getCount() > 0) {
  42. Toast.makeText(getBaseContext(), "Login Berhasil", 0).show();
  43. sqlite2.getWritableDatabase().execSQL("update login set status='masuk'");
  44. startActivity(new Intent(getBaseContext(), MenuActivity.class));
  45. finish();
  46. return;
  47. }
  48. Toast.makeText(getBaseContext(), "Login Gagal", 0).show();
  49. }
  50. });
  51. batal.setOnClickListener(new View.OnClickListener() {
  52. public void onClick(View arg0) {
  53. user.setText("");
  54. pass.setText("");
  55. user.requestFocus();
  56. }
  57. });
  58.  
  59. keluar.setOnClickListener(new View.OnClickListener() {
  60.  
  61. @Override
  62. public void onClick(View arg0) {
  63. // TODO Auto-generated method stub
  64. finish();
  65. moveTaskToBack(true);
  66. }
  67. });
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement