Ok so this is not my first for loop in Java, I have been coding for over a year now but for some reasons I cannot seem to get the idea here, have a drawer which contains categories, each category can/cannot have a description, if a User tries to add a category that exists, the program first checks if the description is the same, if it is, it prompts the user to change either description or Category, below is my code, first time I run it, it works properly second time, it prompts users the user but also adds the category instead of returning, any help will be highly appreciated. `
private void addCategory(String category, String description)
{
if(drawer.getItems().isEmpty()) {
addDrawerItem(category, description);
}else {
for (int i = 0; i < drawer.getItems().size(); i++) {
if (category.toUpperCase().equals(drawer.getItem(i).getTextPrimary())
&& description.equals(drawer.getItem(i).getTextSecondary())) {
Toast.makeText(getBaseContext(), "Category with same description exists", Toast.LENGTH_SHORT).show();
}else {
addDrawerItem(category, description);
return;
}
}
}
}`
Aucun commentaire:
Enregistrer un commentaire