Public void insertPressed(View view) {



Download 103.36 Kb.
Page2/3
Date11.05.2021
Size103.36 Kb.
#56601
1   2   3
MOBILEDEV
EmployeeDao.java
1/ Add DAO functions to delete a single employee by id

2/ Add DAO function to delete all employees


// SQL to delete everything?

@Query("DELETE FROM employees")

public void deleteAll();
// SQL to delete by id?

@Query("DELETE FROM employees WHERE id = :empId")

public void deleteEmployeeById(int empId);

Main Activity:
1/ Call the DAO functions in your button click handlers
public void deleteByIdPressed(View view) {

   // 1. Get the id from ther userinterface

   EditText etId = findViewById(R.id.etId);

   if (etId.getText().toString().isEmpty()) {

       Log.d("ABC", "Sorry, you must provide an id");

       return;

   }
   // 2. Call the corresponding delete function

   int id = Integer.parseInt(etId.getText().toString());

   empDAO.deleteEmployeeById(id);

   Log.d("ABC", "Delete finished, check database to confirm it worked.");
}

public void deleteAllPressed(View view) {

   empDAO.deleteAll();

   Log.d("ABC", "All employees deleted");

}



Download 103.36 Kb.

Share with your friends:
1   2   3




The database is protected by copyright ©ininet.org 2024
send message

    Main page