Get rid of annoying EditText focus - android

I have a pretty big ScrollView that consists of EditTexts and Spinners.
I have a huge problem with EditText focus that has been driving me nuts for the last 2 days. The issue is:
After editing an EditText, press 'back' to close the keyboard (the EditText) still remains focused, so when I scroll down to a Spinner and pick an item, the ScrollView jumps back to the last focused EditText, which is very annoying.
I've looked all over StackOverflow and tried everything. I've tried clearFocus() on the EditText after editing, but the focus just jumps to another EditText. I put android:focusableInTouchMode="true" and android:focusable="true"on the parent LinearLayout, hoping that it would steal the focus. Still doesn't work.
I have tried setting click listeners on spinners, and calling requestFocus() when clicking them. Nothing works.
Please help.

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?

Animate or scroll EditText to top of screen

I have a DialogFragment, where is a ScrollView with some EditText fields. If the user press on the last one, it should be moved to top of the dialog, right under the title.
If I just scroll to this field with scrollView.smoothScrollTo(0, view), it just appears over the soft keyboard, but other fields over this last one are still shown.
If I make the visibility of all fields above "GONE", it works fine, but the user can't scroll back, but I need it.
I don't know if it is possible on Android at all. Can anybody please help me? I spent three days on this problem but could not find the solution. Any help will be appreciated!
EDIT: screenshots
this is what I have:
and what I need:

EditText inside ListView loses focus on keyboard show

EditText inside ListView loses and gains focus 3 or 4 times when keyboard shows up. I have properly configured ListView (beforeDescendants) and Activity (adjustPan). I have over 500 items in ListView so I can't use ScrollView. I've made some research and I found that people had same problem. What keeps stealing focus during keyboard show up? Are views invalidated in that process?

Android - how to keep an AutoCompleteTextView from keeping focus

I have a pretty complex layout that has multiple types of views and I have one AutoCompleteTextView that keeps focus. I have relativeLayouts which I keep set to GONE and then when I expand them the screen shoots back up to the autoCompleteTextView which is annoying when you are way down the view. How can I keep the AutocompleteTextView from keeping focus without setting it to not being able to take focus because when you do this you cant click on it to write in it. I tried setting it to not take focus and adding an onclick listener where I basically said if not in focus take focus but that didnt work. I would like to be able to have it so I can start the activity with the AutoCompleteTextView having no focus and then when someone clicks on it they can write in it and when they are done it loses focus. Any help on the matter would be much appreciated.
Place this on its parents layout (like linearLayout):
android:focusable="true"
android:focusableInTouchMode="true"
This way LinearLayout will take focus when user join your activity and the keyboard will not show.

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