Android EditText inside ScrollView get auto focus - android

I have a page that contains a main ScrollView, and within that there are 5 EditText controls and a few spinner controls.
Whenever I select some value in the spinner controls, the page scrolls automatically and the EditText gets the focus. How can I prevent this?
I have also tried calling the clearfocus method on the EditText that receives the autofocus, but that doesn't help.

Related

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

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?

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?

Soft Keyboard next press not moving to the edittext below it but moves rightwards

I have an layout in which have multiple editTexts. I want that when next of soft keyboard's is pressed the focus should move to the edittext below the edittext which previously had focus. But when next is pressed, the focus moves to the edittext which is placed to the right of the edittext which previously had focus. I found that it moves down if I remove the onEditorAction Listener from the edittext. But the problem is that I have some functionality which is dependent on onEditorAction Listener and hence can not remove the onEditorAction Listener. So please provide some solution for this.
You can manually set where focus should move:
EditText et2=(EditText)findViewById(R.id.et2);
EditText et3=(EditText)findViewById(R.id.et3);
// Set keyboard next buttons
et1.setNextFocusDownId(R.id.et2);
But you have to be careful about setting android:nextFocusDown in your XML layout because errors will be thrown if the objects you are referencing haven't been created yet.
Info from here

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.

Categories

Resources