我怎样才能把更新的电话号码,我拿起我的Android应用领域?(How can I put the

2019-10-22 01:41发布

我怎样才能把更新的电话号码,我选场? 我有选择器返回的电话号码,但在错误的领域。

选择联系人后,电话号码被放置在错误的领域。

负责该联系人挑选逻辑我的片段是在我的回购https://github.com/jackygrahamez/MayDay/blob/gradle2/app/src/main/java/com/mayday/md/common/ContactPickerFragment.java

我会如何重构这个代码就摆在正确的字段中的数字?

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

新的线索 :我注意到请求的代码返回根据场我挑选不同的值:第一字段requestCode 65636,第二场requestCode 131172,第三字段requestCode 196708

Answer 1:

您当前的设置有WizardActivity作为父活动, SetupContactsFragment作为一个片段,并ContactPickerFragment小时候片段。 当ContactPickerFragment发出startActivityForResult(...)调用, onActivityResult(...)回调在收到WizardActivity

问题:

首先, WizardActivity's成员变量contactPickerFragment从未使用过。 这是不是你的用户界面的一部分。 所以,调用contactPickerFragment.onActivityResult(....)WizardActivity#onActivityResult(...)什么也不做除了打印一些日志语句。 此外,调用super.onActivityResult(...)全部丢失。 正确的方法是检查是否请求代码的颁发WizardActivity 。 如果不是,调用父类方法将路由onActivityResult(..)调用片段SetupContactsFragment

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    // currently, WizardActivity does not deal with 
    // any onActivityResult callbacks
    super.onActivityResult(requestCode, resultCode, data);
}

SetupContactsFragment现在可以收到onActivityResult(...)回调。 不过,我们需要识别和派遣onActivityResult(...)以正确的子片段。 这样做的一个方法是将一个不同的分配requestCode到每个儿童的片段。 里面SetupContactsFragment#onActivityResult(...)我们遍历所有子片段,并发出自己的调用onActivityResult(...)方法。 既然我们已经分配了不同的requestCode每个片段,只有这些调用之一将被处理。

不过,我不明白为什么你需要三个相同的子片段,各持一个输入字段和一个按钮。 这些部件都可以成为其中的一部分SetupContactsFragemets' UI。 即使规格从3个触点在未来更改为10,你可以实现一个膨胀和多次增加每一行的方法。

在这种情况下,您将需要3个独特requestCodes 。 基于该上ImageButton被按下时,一个不同的requestCode用于startActivityForResult(...) 里面onActivityResult(...)requestCode将指示其EditText需要更新。



文章来源: How can I put the updated phone number into the field I picked for my Android app?