I have a ViewPager that holds 4 fragments/panels, each half-width of a landscaped screen.
_______________ _______________ _______________ _______________
|1 |2 |3 |4 |
| | | | |
| | | ___________ | ___________ |
| | | | EditText1 | | | EditText2 | |
| | | |___________| | |___________| |
|_______________|_______________|_______________|_______________|
Panels 3 and 4 each have a single EditText.
At program start, the user is show screens 2 & 3 (they can swipe back to see screen 1,
and screen 4 does not yet exist until a list item on 3 is selected).
So, the view hosting the panels (and associated ViewPager) makes a call to
viewPager.SetCurrentItem(PANEL3,true); // const int PANEL3 = 2; - zero offset
This causes 2 & 3 to be displayed, and gives 3 the focus (which gives EditText1 focus).
When the user selects something on 3 that causes 4 to slide in (so that now 3 & 4 are showing),
another call is made in the host view
viewPager.SetCurrentItem(PANEL4,true); // const int PANEL4 = 3; - zero offset
so that now panel 4 gets the focus (which gives EditText2 the focus).
Here is the issue:
With panels 3 & 4 showing, where EditText2 has focus, if I then click into EditText1, which causes the softkeyboard to popup, focus will revert back to EditText2 (the cursor is in EditText2 and any typing gets entered into it).
I need to know what is causing focus to revert back to EditText2.
I'm speculating that the call to viewPager.SetContentView(PANEL4) is causing the panel focus state to be retained in the ViewPager somewhere, and when the softkeyboard pops up and causes some "refresh" events to fire, the ViewPager is restoring that focus state (which is PANEL4), though I'm not certain. I made a lot of printouts within the host view and each of the panels, and the softkeyboard popup doesn't cause any of the standard lifetime events to be fired, however I do know that the viewPager's OnLayout does fire.
Any help or insight is welcome, thank you.
Cheesebaron:
This is supportive information to help illustrate an inflation issue that happens if one of the views in my solution isn't wrapped in a ViewGroup (LinearLayout) within its associated layout file.
If PagedFragmentRecordNoteBoxInput is not wrapped in a LinearLayout, we have
<?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"/>
and the inflation code in PagedFragmentRecordNoteBox changes to
protected override RecordNoteBoxInput InstantiateInput()
{
View v = _inflater.Inflate(Resource.Layout.PagedFragmentRecordNoteBoxInput, null);
_pagedFragmentFieldInput = (PagedFragmentRecordNoteBoxInput) v;
_pagedFragmentFieldInput.OuterClass = this;
return (RecordNoteBoxInput)_pagedFragmentFieldInput;
}
Which then produces the exception:
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 ()