-
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.23 Save changes to existing pet if it already exists
- Loading branch information
Beginning Android
committed
Aug 23, 2016
1 parent
8d4b875
commit 20d0524
Showing
2 changed files
with
41 additions
and
14 deletions.
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
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
20d0524
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.
Working well.
20d0524
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.
Everytime I want to update a pet, the app seems to process a few seconds and then gets back to the Catalog without having any changes made. Also no toast message was shown.
I double checked the code here. I think there must be something wrong with the update method?
20d0524
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.
when i click on the save button after editing a pet the app stops. What might be the problem behind that?
20d0524
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.
successful work
20d0524
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.
@shanudjn maybe you deleted codes of Uri newUri = getContentResolver().insert(PetEntry.CONTENT_URI, values);
and Toast.makeText(this, getString(R.string.editor_insert_pet_successful),
20d0524
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 list view not updated when i get back from UPDATE mode while add mode list updated well!
can tell what i miss here, and where to add it?
20d0524
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.
@J0k3R101 the issue lies within updatePet() method.. in the very bottom just before the return statement add this snippet if you don't have it already:
20d0524
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.
@maginom , Thank you
i got another question, i was trying to apply a search filter through EditText on the ListView result to target a specific pet but didn't work at all, have you tried anything like that, or help me out?
20d0524
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.
nice work
20d0524
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.
@shanudjn There might be an error in your PetProvider class. If you are unable to find it, then compare your PetProvider class with the official one.
20d0524
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.
My code is showing NullPointerException at this line:
Uri currentPetUri = intent.getData();
Plz help..
My Editor Activity Code:
package com.example.pets;
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.LoaderManager;
import android.support.v4.app.NavUtils;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;
import com.example.pets.data.PetContract.PetEntry;
/**
Allows user to create a new pet or edit an existing one.
*/
public class EditorActivity extends AppCompatActivity implements LoaderManager.LoaderCallbacks {
Uri currentPetUri;
/**
*/
// private Uri mCurrentPetUri;
/**
*/
private EditText mNameEditText;
/**
*/
private EditText mBreedEditText;
/**
*/
private EditText mWeightEditText;
/**
*/
private Spinner mGenderSpinner;
private int mGender = 0;
@OverRide
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_editor);
// android.support.v4.app.LoaderManager loaderManager = getSupportLoaderManager();
//
// loaderManager.initLoader(0, null, this);
}
// if (mCurrentPetUri == null) {
// // This is a NEW pet, so insert a new pet into the provider,
// // returning the content URI for the new pet.
// Uri newUri = getContentResolver().insert(PetEntry.CONTENT_URI, values);
//
// // Show a toast message depending on whether or not the insertion was successful.
// if (newUri == null) {
// // If the new content URI is null, then there was an error with insertion.
// Toast.makeText(this, getString(R.string.editor_insert_pet_failed),
// Toast.LENGTH_SHORT).show();
// } else {
// // Otherwise, the insertion was successful and we can display a toast.
// Toast.makeText(this, getString(R.string.editor_insert_pet_successful),
// Toast.LENGTH_SHORT).show();
// }
// } else {
// // Otherwise this is an EXISTING pet, so update the pet with content URI: mCurrentPetUri
// // and pass in the new ContentValues. Pass in null for the selection and selection args
// // because mCurrentPetUri will already identify the correct row in the database that
// // we want to modify.
// int rowsAffected = getContentResolver().update(mCurrentPetUri, values, null, null);
//
// // Show a toast message depending on whether or not the update was successful.
// if (rowsAffected == 0) {
// // If no rows were affected, then there was an error with the update.
// Toast.makeText(this, getString(R.string.editor_update_pet_failed),
// Toast.LENGTH_SHORT).show();
// } else {
// // Otherwise, the update was successful and we can display a toast.
// Toast.makeText(this, getString(R.string.editor_update_pet_successful),
// Toast.LENGTH_SHORT).show();
// }
// }
}
}
20d0524
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.
when i try to update the values , and click the save button the app crashes
and it throws an exception for invalid pet gender
when i ran the debugger the values i changed shows except for the gender it shows this value "gender" -> "2131230845"
this is the code for my editor activity
public class EditorActivity extends AppCompatActivity implements LoaderManager.LoaderCallbacks {
// check whether if the intent either for adding new pet or edit existing pet
if (petUri == null ){
}
20d0524
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.
check savePet() method , specially the if else