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?
Related
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)
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
I have an EditText. When I click on it, the input keyboard shows up with the EditText directly above it. I want the keyboard to show up a little bit further down at another View, as if the keyboard is focusing on that. Is there a way to handle this?
My use case is I have two EditTexts and a Button in vertical LinearLayout. I want it so that when I click on either of the EditTexts, the keyboard will popup and still show all three Views.
Best practice, you won't want that, i.e showing all views while the keyboard is showing. This will force android to squeeze the views when there isn't enough space.
Best option is try adding paddingBottom to your EditText an example being android:paddingBottom="15dp" This should align the keyboard 15 pixels below your EditText.
You could also use ScrollView as suggested above which allows android to auto handle vertical scrolling for you.
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.
I am currently using an ExpandableListView with a EditText as a child item. I want to give focus to the EditText when the item is expanded and automatically display the keyboard.(This turned out to be more difficult than what I expected. I can give focus to the EditText(using this post Focusable EditText inside ListView), but the keyboard is either never shown or it blinks and then hides itself).
Is a ListView the best approach to do this? Should I rather be looking at creating dynamic views inside a LinearLayout of a ScrollView?
Any suggestions/Ideas?
Sounds like some other view other than your TextView is receiving focus after your TextView receives focus. I would debug by overriding onFocus events on some Views and seeing if they get hit after your TextView.