我有一个ViewPager可以保存4个片段/面板,每个半角的园景画面。ViewPager焦点问题
_______________ _______________ _______________ _______________
|1 |2 |3 |4 |
| | | | |
| | | ___________ | ___________ |
| | | | EditText1 | | | EditText2 | |
| | | |___________| | |___________| |
|_______________|_______________|_______________|_______________|
面板3和4每个都有一个EditText。
在程序开始时,用户显示屏幕2 & 3(它们可以滑动回到看到屏幕1, 和屏幕4,直到选择3上的列表项不存在)。
所以,承载板(和相关联的ViewPager)的视图使得到
viewPager.SetCurrentItem(PANEL3,true); // const int PANEL3 = 2; - zero offset
这会导致显示2 & 3,并给出3的焦点(其给出EditText1焦点)的呼叫。
当用户选择3的东西,使得4至在滑动(使得现在3 & 4示出), 另一个呼叫在宿主视图
viewPager.SetCurrentItem(PANEL4,true); // const int PANEL4 = 3; - zero offset
以至于现在面板4得到由焦点(这给了EditText2焦点)。
这里是问题:
随着面板3 & 4显示,在EditText2具有焦点,如果我再点击进入EditText1,这将导致softkeyboard到弹出,焦点将回到EditText2 (光标在EditText2中,任何键入都会被输入)。
我需要知道什么导致焦点恢复到EditText2。
我在猜测对viewPager.SetContentView(PANEL4)的调用会导致面板焦点状态被保留在ViewPager的某个地方,当softkeyboard弹出并导致一些“刷新”事件触发时,ViewPager正在恢复焦点状态(即PANEL4),尽管我不确定。我在主机视图和每个面板中都做了很多打印输出,并且softkeyboard弹出窗口不会导致任何标准生命周期事件被触发,但是我确实知道viewPager的OnLayout会触发。
欢迎任何帮助或见解,谢谢。
Cheesebaron:
这是支持信息,以帮助其布局相关文件中说明,如果发生在我的解决方案的意见一个不裹在一个ViewGroup(LinearLayout中)的通货膨胀问题。
如果PagedFragmentRecordNoteBoxInput不包裹在LinearLayout中,我们有
<?xml version="1.0" encoding="utf-8"?>
<FieldInspection.Droid.Views.Custom.PagedFragmentRecordNoteBox.PagedFragmentRecordNoteBoxInput
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fi_record_note_box_input"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFFFF"
android:gravity="top"
android:textSize="20sp"
android:textColor="#FF000000"
android:layout_margin="20dip"/>
和充气代码PagedFragmentRecordNoteBox更改
protected override RecordNoteBoxInput InstantiateInput()
{
View v = _inflater.Inflate(Resource.Layout.PagedFragmentRecordNoteBoxInput, null);
_pagedFragmentFieldInput = (PagedFragmentRecordNoteBoxInput) v;
_pagedFragmentFieldInput.OuterClass = this;
return (RecordNoteBoxInput)_pagedFragmentFieldInput;
}
然后产生除外:
07-02 16:21:32.494: I/MonoDroid(18642): UNHANDLED EXCEPTION: Android.Views.InflateException: Exception of type 'Android.Views.InflateException' was thrown.
07-02 16:21:32.494: I/MonoDroid(18642): at Android.Runtime.JNIEnv.CallObjectMethod (intptr,intptr,Android.Runtime.JValue[]) <0x00080>
07-02 16:21:32.494: I/MonoDroid(18642): at Android.Views.LayoutInflater.Inflate (int,Android.Views.ViewGroup) <0x0018f>
07-02 16:21:32.494: I/MonoDroid(18642): at FieldInspection.Droid.Views.Custom.PagedFragmentRecordNoteBox.InstantiateInput() <0x0002b>
07-02 16:21:32.494: I/MonoDroid(18642): at FieldInspection.Droid.Views.Custom.RecordNoteBox.Init (Android.Content.Context) <0x00063>
07-02 16:21:32.494: I/MonoDroid(18642): at FieldInspection.Droid.Views.Custom.RecordNoteBox..ctor (Android.Content.Context,Android.Util.IAttributeSet) <0x0002f>
07-02 16:21:32.494: I/MonoDroid(18642): at FieldInspection.Droid.Views.Custom.PagedFragmentRecordNoteBox..ctor (Android.Content.Context,Android.Util.IAttributeSet) <0x00023>
07-02 16:21:32.494: I/MonoDroid(18642): at (wrapper dynamic-method) object.705e129e-2c0d-42db-87f7-db1842b85d7c (intptr,object[]) <0x0005f>
07-02 16:21:32.494: I/MonoDroid(18642): at Java.Interop.TypeManager.n_Activate (intptr,intptr,intptr,intptr,intptr,intptr) <0x000f7>
07-02 16:21:32.494: I/MonoDroid(18642): at (wrapper native-to-managed) Java.Interop.TypeManager.n_Activate (intptr,intptr,intptr,intptr,intptr,intptr) <0x0006f>
07-02 16:21:32.494: I/MonoDroid(18642): at (wrapper delegate-invoke) <Module>.invoke_intptr__this___intptr_intptr_intptr_JValue[] (intptr,intptr,intptr,Android.Runtime.JValue[]) <0x000ab>
07-02 16:21:32.494: I/MonoDroid(18642): at Android.Runtime.JNIEnv.CallObjectMethod (intptr,intptr,Android.Runtime.JValue[]) <0x00053>
07-02 16:21:32.494: I/MonoDroid(18642): at Android.Views.LayoutInflater.Inflate (int,Android.Views.ViewGroup,bool) <0x001f3>
07-02 16:21:32.494: I/MonoDroid(18642): at FieldInspection.Droid.Views.ParcelRecordDetailInspectionView.Render() <0x0002f>
07-02 16:21:32.494: I/MonoDroid(18642): at FieldInspection.Droid.Views.ParcelRecordDetailInspectionView.OnCreateView (Android.Views.LayoutInflater,Android.Views.ViewGroup,Android.OS.Bundle) <0x000af>
07-02 16:21:32.494: I/MonoDroid(18642): at Android.App.Fragment.n_OnCreateView_Landroid_view_LayoutInflater_Landroid_view_ViewGroup_Landroid_os_Bundle_ (intptr,intptr,intptr,intptr,intptr) <0x0009f>
07-02 16:21:32.494: I/MonoDroid(18642): at (wrapper dynamic-method) object.5d994140-166d-44ce-ac16-71f1e1698262 (intptr,intptr,intptr,intptr,intptr) <0x0005b>
07-02 16:21:32.494: I/MonoDroid(18642): --- End of managed exception stack trace ---
07-02 16:21:32.494: I/MonoDroid(18642): android.view.InflateException: Binary XML file line #5: Error inflating class FieldInspection.Droid.Views.Custom.PagedFragmentRecordNoteBox.PagedFragmentRecordNoteBoxInput
07-02 16:21:32.494: I/MonoDroid(18642): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
07-02 16:21:32.494: I/MonoDroid(18642): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
07-02 16:21:32.494: I/MonoDroid(18642): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
07-02 16:21:32.494: I/MonoDroid(18642): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
07-02 16:21:32.494: I/MonoDroid(18642): at mono.android.TypeManager.n_activate(Native Method)
07-02 16:21:32.494: I/MonoDroid(18642): at mono.android.TypeManager.Activate(TypeManager.java:7)
07-02 16:21:32.494: I/MonoDroid(18642): at fieldinspection.droid.views.custom.PagedFragmentRecordNoteBox.<init>(PagedFragmentRecordNoteBox.java:29)
07-02 16:21:32.494: I/MonoDroid(18642): at java.lang.reflect.Constructor.constructNative(Native Method)
07-02 16:21:32.494: I/MonoDroid(18642): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
07-02 16:21:32.494: I/MonoDroid(18642): at android.view.LayoutInflater.createView(LayoutInflater.java:586)
07-02 16:21:32.494: I/MonoDroid(18642): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
07-02 16:21:32.494: I/MonoDroid(18642): at android.view.LayoutInflater.parseInclude(LayoutInflater.java:800)
07-02 16:21:32.494: I/MonoDroid(18642): at android.view.LayoutInflater.rInflate(LayoutInflater.java:729)
07-02 16:21:32.494: I/MonoDroid(18642): at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
07-02 16:21:32.494: I/MonoDroid(18642): at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
07-02 16:21:32.494: I/MonoDroid(18642): at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
07-02 16:21:32.494: I/MonoDroid(18642): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
07-02 16:21:32.494: I/MonoDroid(18642): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
07-02 16:21:32.494: I/MonoDroid(18642): at fieldinspection.droid.views.ParcelRecordDetailInspectionView.n_onCreateView(Native Method)
07-02 16:21:32.494: I/MonoDroid(18642): at fieldinspection.droid.views.ParcelRecordDetailInspectionView.onCreateView(ParcelRecordDetailInspectionView.java:52)
07-02 16:21:32.494: I/MonoDroid(18642): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:828)
07-02 16:21:32.494: I/MonoDroid(18642): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1032)
07-02 16:21:32.494: I/MonoDroid(18642): at android.app.BackStackRecord.run(BackStackRecord.java:622)
07-02 16:21:32.494: I/MonoDroid(18642): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1382)
07-02 16:21:32.494: I/MonoDroid(18642): at android.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:437)
07-02 16:21:32.494: I/MonoDroid(18642): at android.support.v13.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:167)
07-02 16:21:32.494: I/MonoDroid(18642): at android.supp
07-02 16:21:32.504: E/mono(18642): Unhandled Exception:
07-02 16:21:32.504: E/mono(18642): Android.Views.InflateException: Exception of type 'Android.Views.InflateException' was thrown.
07-02 16:21:32.504: E/mono(18642): at Android.Runtime.JNIEnv.CallObjectMethod (intptr,intptr,Android.Runtime.JValue[]) <0x00080>
07-02 16:21:32.504: E/mono(18642): at Android.Views.LayoutInflater.Inflate (int,Android.Views.ViewGroup) <0x0018f>
07-02 16:21:32.504: E/mono(18642): at FieldInspection.Droid.Views.Custom.PagedFragmentRecordNoteBox.InstantiateInput() <0x0002b>
07-02 16:21:32.504: E/mono(18642): at FieldInspection.Droid.Views.Custom.RecordNoteBox.Init (Android.Content.Context) <0x00063>
07-02 16:21:32.504: E/mono(18642): at FieldInspection.Droid.Views.Custom.RecordNoteBox..ctor (Android.Content.Context,Android.Util.IAttributeSet) <0x0002f>
07-02 16:21:32.504: E/mono(18642): at FieldInspection.Droid.Views.Custom.PagedFragmentRecordNoteBox..ctor (Android.Content.Context,Android.Util.IAttributeSet) <0x00023>
07-02 16:21:32.504: E/mono(18642): at (wrapper dynamic-method) object.705e129e-2c0d-42db-87f7-db1842b85d7c (intptr,object[]) <0x0005f>
07-02 16:21:32.504: E/mono(18642): at Java.Interop.TypeManager.n_Activate (intptr,intptr,intptr,intptr,intptr,intptr) <0x000f7>
07-02 16:21:32.504: E/mono(18642): at (wrapper native-to-managed) Java.Interop.TypeManager.n_Activate (intptr,intptr,intptr,intptr,
07-02 16:21:32.504: I/mono(18642): [ERROR] FATAL UNHANDLED EXCEPTION: Android.Views.InflateException: Exception of type 'Android.Views.InflateException' was thrown.
07-02 16:21:32.504: I/mono(18642): at Android.Runtime.JNIEnv.CallObjectMethod (intptr,intptr,Android.Runtime.JValue[]) <0x00080>
07-02 16:21:32.504: I/mono(18642): at Android.Views.LayoutInflater.Inflate (int,Android.Views.ViewGroup) <0x0018f>
07-02 16:21:32.504: I/mono(18642): at FieldInspection.Droid.Views.Custom.PagedFragmentRecordNoteBox.InstantiateInput() <0x0002b>
07-02 16:21:32.504: I/mono(18642): at FieldInspection.Droid.Views.Custom.RecordNoteBox.Init (Android.Content.Context) <0x00063>
07-02 16:21:32.504: I/mono(18642): at FieldInspection.Droid.Views.Custom.RecordNoteBox..ctor (Android.Content.Context,Android.Util.IAttributeSet) <0x0002f>
07-02 16:21:32.504: I/mono(18642): at FieldInspection.Droid.Views.Custom.PagedFragmentRecordNoteBox..ctor (Android.Content.Context,Android.Util.IAttributeSet) <0x00023>
07-02 16:21:32.504: I/mono(18642): at (wrapper dynamic-method) object.705e129e-2c0d-42db-87f7-db1842b85d7c (intptr,object[]) <0x0005f>
07-02 16:21:32.504: I/mono(18642): at Java.Interop.TypeManager.n_Activate (intptr,intptr,intptr,intptr,intptr,intptr) <0x000f7>
07-02 16:21:32.504: I/mono(18642): at (wrapper native-to-managed) Java.Interop.TypeManager.n_Activate (intptr,intptr,i
07-02 16:21:32.524: W/InputDispatcher(215): channel '41b69d78 net.monocross.fieldinspection/fieldinspection.droid.FieldInspectionMain (server)' ~ Consumer closed input channel or an error occurred. events=0x8
07-02 16:21:32.524: E/InputDispatcher(215): channel '41b69d78 net.monocross.fieldinspection/fieldinspection.droid.FieldInspectionMain (server)' ~ Channel is unrecoverably broken and will be disposed!
07-02 16:21:32.524: W/InputDispatcher(215): Attempted to unregister already unregistered input channel '41b69d78 net.monocross.fieldinspection/fieldinspection.droid.FieldInspectionMain (server)'
07-02 16:21:32.524: D/Zygote(116): Process 18642 exited cleanly (1)
07-02 16:21:32.524: W/InputDispatcher(215): channel '41aef860 net.monocross.fieldinspection/fieldinspection.droid.views.CalendarView (server)' ~ Consumer closed input channel or an error occurred. events=0x8
07-02 16:21:32.524: E/InputDispatcher(215): channel '41aef860 net.monocross.fieldinspection/fieldinspection.droid.views.CalendarView (server)' ~ Channel is unrecoverably broken and will be disposed!
07-02 16:21:32.524: W/InputDispatcher(215): Attempted to unregister already unregistered input channel '41aef860 net.monocross.fieldinspection/fieldinspection.droid.views.CalendarView (server)'
07-02 16:21:32.524: I/ActivityManager(215): Process net.monocross.fieldinspection (pid 18642) has died.
我想我可能会拥有它。当用户选择其中一个EditText时,我需要从包含单击的EditText的片段/面板回调主机活动,并调用viewPager.SetCurrentItem()来更新当前面板。然后,当软键触发视图重绘(请参阅下面的堆栈跟踪)并因此请求焦点时,正确的面板将被聚焦。 – samosaris 2013-03-01 18:32:37