Advertisement
Putra-Kun123

LoginActivity.java

Feb 23rd, 2020
8,785
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 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.view.View.OnClickListener;
  10. import android.widget.Button;
  11. import android.widget.EditText;
  12. import android.widget.Toast;
  13.  
  14. public class LoginActivity extends Activity {
  15. SQLiteDatabase db;
  16. Database sqlite, sqlite2;
  17. EditText user,pass;
  18. Button login, keluar;
  19. Cursor cursor;
  20.  
  21. @SuppressWarnings("unused")
  22.  
  23. public void onCreate(Bundle savedInstanceState) {
  24. super.onCreate(savedInstanceState);
  25. setContentView(R.layout.login);
  26. Database sqlite=new Database(this);
  27. final SQLiteDatabase db=sqlite.getWritableDatabase();
  28.  
  29. user=(EditText)findViewById(R.id.edusername);
  30. pass=(EditText)findViewById(R.id.edpassword);
  31. login=(Button)findViewById(R.id.btnlogin);
  32. keluar=(Button)findViewById(R.id.btnkeluar);
  33. sqlite2=new Database(this);
  34.  
  35. login.setOnClickListener(new View.OnClickListener() {
  36.  
  37. public void onClick(View arg0) {
  38.  
  39. SQLiteDatabase db=sqlite2.getReadableDatabase();
  40. cursor=db.rawQuery("Select*from login where username='"+ user.getText().toString() +
  41. "' and password= '" + pass.getText().toString() +"'", null);
  42. cursor.moveToFirst();
  43. if (cursor.getCount()>0){
  44. Toast.makeText(getBaseContext(), "Login Berhasil", Toast.LENGTH_SHORT).show();
  45. Intent i=new Intent (getBaseContext(),MenuActivity.class);
  46. startActivity(i);
  47. }else{
  48. Toast.makeText(getBaseContext(), "Login Gagal", Toast.LENGTH_SHORT).show();
  49. }
  50. }
  51. });
  52.  
  53. keluar.setOnClickListener(new OnClickListener() {
  54.  
  55. public void onClick(View arg0) {
  56. finish();
  57.  
  58. }
  59. });
  60.  
  61. }
  62. }
  63.  
  64. //ig harymalau
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement