How can I put the updated phone number into the field I picked? I have the picker returning the phone number but in the wrong field.
After picking a contact the phone number is placed in the wrong field.
My fragment responsible for this contact picker logic is in my repo https://github.com/jackygrahamez/MayDay/blob/gradle2/app/src/main/java/com/mayday/md/common/ContactPickerFragment.java
How might I refactor this code to put the number in the correct field?
02-23 12:47:59.217 12360-12360/com.mayday.md E/WizardActivity﹕ onUserInteraction
02-23 12:47:59.347 12360-12360/com.mayday.md E/WizardActivity﹕ onUserInteraction
02-23 12:47:59.347 12360-12360/com.mayday.md E/WizardActivity.onPause﹕ page = setup-contacts
02-23 12:47:59.347 12360-12360/com.mayday.md E/>>>>>>﹕ assert flagRiseFromPause = true
02-23 12:47:59.387 12360-12360/com.mayday.md D/AbsListView﹕ unregisterIRListener() is called
02-23 12:48:00.657 12360-12360/com.mayday.md D/WizardActivity.onStop﹕ page = setup-contacts
02-23 12:48:00.657 12360-12360/com.mayday.md D/AbsListView﹕ onVisibilityChanged() is called, visibility : 4
02-23 12:48:00.657 12360-12360/com.mayday.md D/AbsListView﹕ unregisterIRListener() is called
02-23 12:48:02.107 12360-12360/com.mayday.md E/ContactPickerFragment﹕ onActivityResult requestCode 65636
02-23 12:48:02.107 12360-12360/com.mayday.md E/ContactPickerFragment﹕ onActivityResult resultCode -1
02-23 12:48:02.107 12360-12360/com.mayday.md E/ContactPickerFragment﹕ onActivityResult data Intent { dat=content://com.android.contacts/data/2369 flg=0x1 }
02-23 12:48:02.117 12360-12360/com.mayday.md E/ContactPickerFragment﹕ onActivityResult id 2369
02-23 12:48:02.117 12360-12360/com.mayday.md E/ContactPickerFragment﹕ onActivityResult name XXX XXXX
02-23 12:48:02.147 12360-12360/com.mayday.md D/dalvikvm﹕ GC_FOR_ALLOC freed 598K, 22% free 29241K/37368K, paused 15ms, total 15ms
02-23 12:48:02.147 12360-12360/com.mayday.md E/WizardActivity﹕ onActivityResult pCur android.content.ContentResolver$CursorWrapperInner@4313d048
02-23 12:48:02.147 12360-12360/com.mayday.md E/ContactPickerFragment﹕ onActivityResult phone xxxxxxxxxx
02-23 12:48:02.147 12360-12360/com.mayday.md E/ContactPickerFragment﹕ onActivityResult phone xxxxxxxxxx
02-23 12:48:02.147 12360-12360/com.mayday.md E/ContactPickerFragment﹕ onActivityResult phoneNumberEditText android.widget.EditText{42c580b0 VFED..CL ........ 0,0-944,156 #7f0b0016 app:id/contact_edit_text}
02-23 12:48:02.147 12360-12360/com.mayday.md E/??????﹕ text changed
02-23 12:48:02.147 12360-12360/com.mayday.md D/WizardActivity.onStart﹕ page = setup-contacts
02-23 12:48:02.147 12360-12360/com.mayday.md E/WizardActivity.onResume﹕ pageId = setup-contacts and flagRiseFromPause = true
02-23 12:48:02.147 12360-12360/com.mayday.md E/WizardActivity.onResume﹕ back button pressed
02-23 12:48:02.147 12360-12360/com.mayday.md D/AbsListView﹕ onVisibilityChanged() is called, visibility : 0
02-23 12:48:02.147 12360-12360/com.mayday.md D/AbsListView﹕ unregisterIRListener() is called
02-23 12:48:02.167 12360-12360/com.mayday.md D/AbsListView﹕ unregisterIRListener() is called
NEW CLUE : I notice that the request code returns different values depending on the field I pick: 1st field requestCode 65636, 2nd field requestCode 131172, 3rd field requestCode 196708
Your current setup has
WizardActivity
as the parent activity,SetupContactsFragment
as a fragment, andContactPickerFragment
as a child-fragment. WhenContactPickerFragment
issues astartActivityForResult(...)
call,onActivityResult(...)
callback is received inWizardActivity
.Problem:
First off,
WizardActivity's
member variablecontactPickerFragment
is never used. It isn't part of your ui. So, callingcontactPickerFragment.onActivityResult(....)
insideWizardActivity#onActivityResult(...)
does nothing other than print a few log statements. Additionally, the call tosuper.onActivityResult(...)
is missing altogether. The correct way would be to check if the request code was issued byWizardActivity
. If it wasn't, calling the super method will route theonActivityResult(..)
call to the fragmentSetupContactsFragment
.SetupContactsFragment
can now receive theonActivityResult(...)
callback. Still, we need to identify and dispatchonActivityResult(...)
to the correct child-fragment. One way of doing this is to assign a differentrequestCode
to each of the child-fragments. InsideSetupContactsFragment#onActivityResult(...)
, we iterate over all child-fragments and issue a call to theironActivityResult(...)
method. Since we have assigned a differentrequestCode
to each fragment, only one of these calls will be processed.However, I don't see why you need three identical child fragments, each holding an input field & a button. These widgets can all be part of
SetupContactsFragemets'
ui. Even if the specifications change from 3 contacts to 10 in the future, you could implement a method that inflates and adds each row multiple times.In this case, you will need 3 unique
requestCodes
. Based on whichImageButton
is pressed, a differentrequestCode
is used forstartActivityForResult(...)
. InsideonActivityResult(...)
, therequestCode
will indicate whichEditText
needs to be updated.