EditText in RecyclerView view is detached when keyboard opened - android

I am attempting to create a long form with a variable number of EditText elements inside a RecyclerView. The layout consists of a FrameLayout, a RecyclerView for the form sections, then a nested RecyclerView inside of a CardView to hold all of the form elements for that section (see animation below).
Normally when an element is focused the keyboard will appear, the window is resized, and the view is scrolled so the element appears above the keyboard. The issue I am having is when an element is selected at the bottom of the screen and top of a section the window is resized and the RecyclerView detaches the section's view, causing the EditText to not exist when it tries to focus. This manifests itself as the keyboard popping open momentarily then closing as focus is returned to the FrameLayout.
I am using android:windowSoftInputMode="adjustResize" in my activity and do not want to use adjustPan because it does not provide the best user experience.
I've tried adding a click listener to the EditText then scrolling the RecyclerView up so that the view won't get destroyed when the window resizes but this feels hacky and it is hard to detect precisely how far up the RecyclerView should be scrolled. You also get some weird jumps. In order to do this you have to turn off the focusability of the EditText which isn't ideal either because it breaks navigation and accessibility.
Trying to do something like recyclerView.getRecycledViewPool().setMaxRecycledViews(0, SECTION_COUNT); doesn't work either because it doesn't prevent the views from being detached.
How do I keep the view from being detached when the window is resized for the keyboard so the EditText receives focus?

I solve this with by
android.os.Handler().postDelayed({recycle.smoothScrollToPosition(0)},100)

Related

Android - How to resize only certain views when keyboard visibility changes

I have an Activity with three Fragment and they are controlled by Tabs at the bottom.
One of the fragments needs the keyboard and so I would like to resize the fragment recycler view when the keyboard is visible, so that the last item in the recycler view is visible above the keyboard (after scrolling).
But if in the AndroidManifest.xml, I specify
android:windowSoftInputMode="adjustResize"
or
android:windowSoftInputMode="adjustPan"
The bottom tabs also become visible above the keyboard.
I even tried to use OnGlobalLayoutListener to check when the keyboard is visible and then adjust height of the recycler view accordingly. But this also does not work, since, OnGlobalLayoutListener is called only when
android:windowSoftInputMode="adjustPan" or android:windowSoftInputMode="adjustResize"
are used, which defeats the purpose in this case.
Is there any way such that the view of the Fragment is resized/adjusted but not the activity view (bottom tabs)?
Thanks
So this is how I solved it.
The keyboard changes are received in OnGlobalLayoutListener when
android:windowSoftInputMode="adjustPan"
And it also does not push the bottom tabs above the keyboard.
Thus, it solves the issue at hand.
Thanks

Android: prevent keyboard from hiding EditText

I have an Activity which its layout contains a ScrollView with several Fragments and some of the Fragments have RecyclerView which items in it contains EditText inside them.
I set the android:windowSoftInputMode to stateHidden|adjustPan.
It works most of the time well, but on some EditTexts the keyboard hides the text at first, but when starting to type it corrects itself and the screen jumps to the correct position.
UPDATE
I found out that it happens in RecyclerView and not in ListView

EditText forcing ActionBar to hide

An EditText at the bottom of a ListView when pressed, hides the ActionBar. My first problem was to prevent the background image of ListView to shrink. Somehow i overcame my issue. But dnt know how to tackle this one. Can any body guide me? Thanx in advance.
Edit(Explanation)
like a chat window in Viber or Whats App, i have a EditText at the bottom, a ListView in the center and an ActionBar at the top. when i clicked the EditText , the background image shrinks/squeeze. I used adjustPan to overcome this. Its fine. But now, when the soft Keyboard appears, it hides the ActionBar/TitleBar.
Use adjustResize instead of adjustPan. The framework will always try to keep the focused element on-screen by scrolling any parent views if necessary.
If your EditText field is not nested in some sort of scrolling container such as a ScrollView then your layout may be too tall to completely display when the keyboard resizes your activity. Try wrapping your form's layout in a ScrollView. This will also allow your app's content to scroll if it is running on a smaller screen device where it may have similar issues.

How can I disable a layout behind my SlidingDrawer in Android?

I have a SlidingDrawer that pops up from the bottom of the screen and fills the screen about 80%. Even though the SlidingDrawer view is in focus, it is still possible to click on items, buttons and other elements in the view that is behind the SlidingDrawer. When SlidingDrawer is active/pulled up/in focus, I want to disable the entire view behind it so it will not be able to recieve clicks and touches. Is there a good way to disable an entire view? I have tried setEnable(false) and setClickable(false) but neither of them work.
Grab the LinearLayout that holds the contents and add a click listener. Have the click listener respond to clicks (throw away, whatever) - and this then stops it propagating to the view below the sliding drawer - it works for me - and it doesn't block the other items in the drawer.
Other way is to put SlidingDrawer in the RelativeLayout, instead of LinearLayout. And set mySlidingDrawer.bringToFront() in opening method.

EditText above listview, scroll page with keyboard

so i have some elements (including an EditText) above my ListView. The EditText is essentially a custom search field that I implemented to add some extra functionality to the filtering of the ListView. The EditText cannot be a header of the ListView because I don't want it to scroll off screen as you go through the list.
All works well, except on smaller devices. The screen does not scroll when you are entering text in the EditText so you can't see the live-filtering within the ListView.
Usually you would make the parent item in the layout file a ScrollView and define the activity's windowSoftInputMode as adjustResize, but this is not an option due to the fact that I have this ListView within the layout and it is a sin to have a ListView within the ScrollView.
Ideally, I'm looking for a way to make the following happen:
-upon the EditText gaining focus, I'd like it to scroll to the top of the page, and the listview occupy the rest of the screen.
-upon the EditText losing focus I'd like the screen to return to it's default state.
so far, the only real way that I'm coming up with doing this is to manually detect the keyboard showing up and then hide the top of the screen, and then upon detecting the keyboard disappearing i would show it again.
can anyone suggest something better that isn't such a hack?

Categories

Resources