Coding the Fragment classes to use the DataManager class
Add this highlighted code to the InsertFragment class to update the onCreateView function, as follows:
val view = inflater.inflate(
R.layout.content_insert,
container,
false)
// Database and UI code goes here in next chapter
val dm = DataManager(activity!!)
val btnInsert = view.findViewById(R.id.btnInsert) as Button
val editName = view.findViewById(R.id.editName) as EditText
val editAge = view.findViewById(R.id.editAge) as EditText
btnInsert.setOnClickListener(
{
dm.insert(editName.text.toString(),
editAge.text.toString())
}
)
return viewIn the code, we get an instance of our DataManager class and a reference to each of our UI widgets. Then, in the onClick function of the button, we use the insert function to add a new name and age to the database. The values to insert are taken from the two EditText widgets.
Add this highlighted code to the DeleteFragment...