EditText loses focus after resizing ListView when keyboard is displayed - android

I have a ListView that I need to manually resize when the keyboard is displayed.
This works by overwriting the onSizeChanged method and changing the size of the view accordingly. (Thanks to this post How to set size and layout in onSizeChanged?)
However, when the size of the list view is changed the EditText that I clicked on loses its focus and I can't enter any text.
EDIT:
I tried to set the focus of the EditText that had the focus before, however, this doesn't always work, although the method returns true when calling request focus

In onSizeChanged() after resizing the ListView add this line.
editText.requestFocus();

Use edittext.requestfocus() method:
requestFocus();

Related

Spinner losing focus after item is selected

I have a dialog with a bunch of EditTexts and Spinners. They are all inside a ScrollView and the dialog can sometimes be large enough for the scroll bar to be required.
When I select an item from a spinner, it will lose focus and switch to the first EditText in the dialog. When they are all shown on the screen, this is not a big problem, but when the spinner is on the bottom, it will auto scroll to the top to select the first EditText. And that's where it becomes very annoying.
I have tried calling requestFocus() on the spinner inside it's itemSelectedListener but it did not work. I had the same problem with buttons. When they were clicked, the focus would be switched to the first EditText, but requesting focus inside the button's click listener solved it.
EDIT:
I have noticed that the spinners were not focusable. After setting setFocusable and setFocusableInTouchMode to true, the first EditText would no longer get selected, but the viewpoint would still be scrolled to it. How do I prevent this?

View in scrollview gets hidden when requestFocus() is called

I have a ScrollView where there are a number of EditText fields.
When i call requestFocus() on any of those fields, the EditText fields comes into view as the scroll view scrolls by itself, even when the soft keyboard is up.
The problem lies in the fact that i have had to add a separate view above the soft keyboard to accommodate a clear button, and it is that custom view that is hiding the edit text field in focus.
Now, i have to manually scroll the scroll view to see the edit text field in focus.
Please help me to show the edit text field in focus above the custom view which is placed on top of the soft keyboard.
Is there any way to do so ?
EDIT:: This is how i solved this problem.
scrollView.post(new Runnable() {
public void run() {
scrollView.scrollTo(0, scrollView.getBottom()-200);
}
});
and gradually went on decreasing the amount i am subtracting from the scrollView.getBottom() call. This worked fine for me.
In your manifest.xml file, for your activity just add this line:
android:windowSoftInputMode="adjustPan"

windowSoftInputMode adjustPan does not work when EditText is moved/resized

I want to use an EditText to let the user edit input on different positions of a Scrollview (like cells in a spreadsheet). When the softkeyboard is invoked, it moves the screen only as long as the Edittext is on its original location, that was given in the Layout.xml. As soon as I change something like size, location, background, the invoked Keyboard does not move the screen, but covers the Edittext when it is in the way. Same when I use adjustResize.
Is there a solution beside adding an separate EditText on every possible opsition?
Any help welcome.
Its all about the focus of the view, things will work when system know which view have the focus, in scrollview case the focus is on the scrollview hence things will not work accordingly.can see this for more information.

Android Expandable ListView with EditText

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.

When do Android EditText's requestFocus()

I have a number of EditTexts inside a scrollview. In the background these fields are linked to a number of other fields and regularly (once a second or so) the layout has it's textfields updated depending on the values in the EditText.
The problem is if one EditText has focus at the top of the ScrollView and the user scrolls the view done (i.e. so the focused EditText is off screen), but if the update is made to the views, the scroll view moves up to focus on the EditText at the top of the view.
The closest I have got to remedying this is to make the scroll view change focus when scrolling however this is still has the same behaviour but at a reduced scale.
Does anyone have an idea of how I can stop this from happening?
Cheers,
Matt
You can try using EditText#setFocusable around your code that updates the value. I haven't tested this but if the problem is that it is getting focus when you use setText() it may help.

Categories

Resources