public void onClickUpdateData(View view) {
   helper.open();
   if (helper.updateRecord(getId(), getName(), getPhone(), getEmail())) {
     Toast.makeText(this, "Update was successfull", Toast.LENGTH_SHORT).show();
   } else {
     Toast.makeText(this, "Update failed", Toast.LENGTH_SHORT).show();
   }
 }
 public void onClickDeleteRecord(View view) {
   helper.open();
   if (helper.deleteRecord(getId())) {
     Toast.makeText(this, "Delete process succeded", Toast.LENGTH_SHORT).show();
   } else {
     Toast.makeText(this, "Record could not be deleted", Toast.LENGTH_SHORT).show();
   }
   helper.close();
 }
 public void onClickGetRecord(View view) {
   helper.open();
   Cursor c = helper.getSingleRecord((long) getId());
   if (c != null) {
     Toast.makeText(
             this,
             "The name is: "
                 + c.getString(0)
                 + " phone number is "
                 + c.getString(1)
                 + " and enail is"
                 + c.getString(2),
             Toast.LENGTH_SHORT)
         .show();
   } else {
     Toast.makeText(this, "No records found", Toast.LENGTH_SHORT).show();
   }
   helper.close();
 }
 public void onClickGetAllRecords(View view) {
   helper.open();
   Cursor c = helper.getAllRecords();
   if (c != null) {
     do {
       Toast.makeText(
               this,
               "The name is "
                   + c.getString(0)
                   + "\nThe phone is "
                   + c.getString(1)
                   + "\nThe email is "
                   + c.getString(2),
               Toast.LENGTH_SHORT)
           .show();
     } while (c.moveToNext());
   } else {
     Toast.makeText(this, "No records found", Toast.LENGTH_SHORT).show();
   }
   helper.close();
 }
示例#5
0
  public void initControls() {
    login = (Button) findViewById(R.id.loginButton);
    signUp = (Button) findViewById(R.id.signUpButton);
    usernameInput = (EditText) findViewById(R.id.username);
    passwordInput = (EditText) findViewById(R.id.password);
    database = DatabaseHelper.getInstance(getApplicationContext());
    try {
      database.open();
    } catch (SQLException e) {
      e.printStackTrace();
    }
    login.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent startNewActivity = new Intent(getApplicationContext(), HomePage.class);
            username = usernameInput.getText().toString();
            password = passwordInput.getText().toString();
            currentUser = database.findUser(username, password);
            if (currentUser.getFirstName() != null) {
              startNewActivity.putExtra("userID", currentUser.getUserID());
              startActivity(startNewActivity);
              finish();
            } else {
              Toast.makeText(getApplicationContext(), "Incorrect Login", Toast.LENGTH_SHORT).show();
            }
          }
        });

    signUp.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent startNewActivity = new Intent(getApplicationContext(), SignUp.class);
            startActivity(startNewActivity);
          }
        });
  }
示例#6
0
 public void openDb() {
   d1 = d1.getInstance(getActivity());
   d1.open();
 }
 public void onClickInsert(View view) {
   helper.open();
   helper.insertRecord(getName(), getPhone(), getEmail());
   // update method in DatabaseHelper to return long...check if long is -1...conditions
   helper.close();
 }