Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void onClick(View v){
- if (editusername.getText().toString().trim().length() == 0 || editpassword.getText().toString().trim().length() ==0) {
- Toast.makeText(getApplicationContext(), "Semua Kolom harus Diisi", Toast.LENGTH_SHORT).show();}
- else try{ String username = editusername.getText().toString().trim();
- String password = editpassword.getText().toString().trim();
- String query = "Select * From User where username = '"+username+"'";
- if(DbManager.fetch().getCount()>0){
- Toast.makeText(getApplicationContext(), "Already Exist!", Toast.LENGTH_SHORT).show();
- }else{
- DbManager.insert(username, password);
- Toast.makeText(getApplicationContext(), "Added successfully!", Toast.LENGTH_SHORT).show();
- }
- }catch (Exception e) {
- e.printStackTrace();
- }
- public void insert(String usn, String pwd) {
- ContentValues contentValue = new ContentValues();
- contentValue.put(SQLiteHelper.USERNAME, usn);
- contentValue.put(SQLiteHelper.PASSWORD, pwd);
- this.database.insert(SQLiteHelper.TABLE_NAME_USER, null, contentValue);
- }
- public Cursor fetch() {
- Cursor cursor = this.database.query(SQLiteHelper.TABLE_NAME_USER, new String[]{SQLiteHelper._ID, SQLiteHelper.USERNAME, SQLiteHelper.PASSWORD}, null, null, null, null, null);
- if (cursor != null) {
- cursor.moveToFirst();
- }
- return cursor;
- }
Add Comment
Please, Sign In to add comment