-
Notifications
You must be signed in to change notification settings - Fork 717
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1.28 Delete all pets from catalog menu item
- Loading branch information
Beginning Android
committed
Aug 23, 2016
1 parent
c1a4418
commit 311f80d
Showing
1 changed file
with
10 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
311f80d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the Pet Items are get deleted. but list items on the catalog activity have items. Empty View is appeared only after restarting the app again.. may I know the solution.. tried recreate and finish...no use
311f80d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It didn't change after click the button, it is seems the loader hadn't notice the change
311f80d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In CatalogActivity, do something like this
@OverRide
public void onLoadFinished(Loader loader, Cursor data) {
if(data != null && data.moveToFirst()) {
mPetCursorAdapter.swapCursor(data);
} else if(data != null && data.getCount() == 0) {
mPetCursorAdapter.swapCursor(null);
}
}
311f80d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me everything works perfectly.. it returns to the welcome screen as it should ! 👍
It does make much more sense to ask are you sure you want to delete the WHOLE table instead of a single pet but anyway ;D
311f80d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code to refresh the screen are on lines 154 to 182 (click on the expand icon to see hidden lines).
@maginom, to change the text in CatalogActivity to display a different message, add a new string in xml, and then set the message to the new string.
<string name="delete_all_pet_dialog_msg">Delete all pets?</string>
builder.setMessage(R.string.delete_all_pet_dialog_msg);
311f80d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's pretty easy to insert the alert dialog to ask the user if they are sure they want to delete all the pets.
It's a matter of
(I renamed it to showDeleteAllConfirmationDialog() )
I'm surprised how easy it was... considering a few lessons ago it seemed pretty hard.
If you get confused just look at what you did in the EditorActivity for the deleting of a single pet.
311f80d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For those who are not seeing changes on the screen, did you put "notifyChange()" in your PetProvider class? Remember to put that method into your "insert()", "update()" and "delete()" helper method as well as the "setNotificationUri()" in query method.
311f80d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am stuck with my code back when trying to implement the LoaderManager.
I've even copied the code from above and it still doesn't work.
This statement is producing an error:
getLoaderManager().initLoader(PET_LOADER, null, this);
It AndroidStudio it says:
Wrong 3rd argument type.
Found 'com.example.android.petsapp.CatalogActivity'
Required android.app.LoaderManager.LoaderCallbacks<java.lang.object>'
Anyone got any bright ideas?
I have everything imported that I need as far as I know.
311f80d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to use "getSupportLoaderManager()" instead of "getLoaderManager()".
311f80d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can anyone tell me why the app crashes when i press delete all apps option
311f80d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No change in my app whenever I insert data via FAB then toast appears only that is "Pet saved" but home screen shows image / empty view screen .... I am confused don't know what to do ... this code out of my mind.... :(