So basically, I have 2 buttons: Cancel, and Create Recipe. Clicking both would take me back to my home page.
"Create Recipe" requires some EditTexts beforehand to be filled before moving to the homepage and "Cancel"
"Cancel" works fine. But "Create Recipe" crashes the emulator
Below are my codes
// createRecipe button onClickListener
Button createButton = findViewById(R.id.createButton);
createButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Checks if there are empty fields
if (isEmpty(etRecipeName, etDuration, etIngredient, etDesc) == false) {
Toast.makeText(MainActivity.this, "There are empty fields. Please fill up all fields",
Toast.LENGTH_SHORT).show();
}
// Create the recipe
else {
createRecipe(etRecipeName, etDuration, etIngredient, etDesc);
Toast.makeText(MainActivity.this, "Recipe Created", Toast.LENGTH_SHORT).show();
Intent changePage = new Intent(MainActivity.this, afterCancel.class);
startActivity(changePage);
}
}
});
// Cancel button onClickListener
Button cancelButton = findViewById(R.id.cancelButton);
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent changePage = new Intent(MainActivity.this, afterCancel.class);
startActivity(changePage);
}
});
For my home page, its just a
this.getintent()