Guest User

Untitled

a guest
Nov 29th, 2018
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. public void onClick(View v){
  2. if (editusername.getText().toString().trim().length() == 0 || editpassword.getText().toString().trim().length() ==0) {
  3. Toast.makeText(getApplicationContext(), "Semua Kolom harus Diisi", Toast.LENGTH_SHORT).show();}
  4.  
  5. else try{ String username = editusername.getText().toString().trim();
  6. String password = editpassword.getText().toString().trim();
  7. String query = "Select * From User where username = '"+username+"'";
  8. if(DbManager.fetch().getCount()>0){
  9. Toast.makeText(getApplicationContext(), "Already Exist!", Toast.LENGTH_SHORT).show();
  10. }else{
  11. DbManager.insert(username, password);
  12.  
  13. Toast.makeText(getApplicationContext(), "Added successfully!", Toast.LENGTH_SHORT).show();
  14.  
  15. }
  16.  
  17. }catch (Exception e) {
  18. e.printStackTrace();
  19. }
  20.  
  21. public void insert(String usn, String pwd) {
  22. ContentValues contentValue = new ContentValues();
  23. contentValue.put(SQLiteHelper.USERNAME, usn);
  24. contentValue.put(SQLiteHelper.PASSWORD, pwd);
  25. this.database.insert(SQLiteHelper.TABLE_NAME_USER, null, contentValue);
  26. }
  27.  
  28.  
  29. public Cursor fetch() {
  30. Cursor cursor = this.database.query(SQLiteHelper.TABLE_NAME_USER, new String[]{SQLiteHelper._ID, SQLiteHelper.USERNAME, SQLiteHelper.PASSWORD}, null, null, null, null, null);
  31. if (cursor != null) {
  32. cursor.moveToFirst();
  33. }
  34. return cursor;
  35. }
Add Comment
Please, Sign In to add comment