When do Android EditText's requestFocus() - android

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.

Related

How to implement an EditText containing TextViews

I have trouble implementing the EditText below.
This would be the behavior of the EditText.
After the user enters a text and presses done, a textview with a grey background would be created in front of the edittext. eg. Apple, Banana. The cursor would then reposition in front of the created TextView.
The user would be able to place the cursor between Apple and Banana and upon backpress, the textview before the cursor would be removed.
In case the width of the elements inside the EditText exceeds the screen, you would be able to scroll horizontally inside.
I have tried creating a parent LinearLayout with an underline background which has a RecyclerView and EditText inside. Upon enter, I would add an element in the RecyclerView and increase it's width while the EditText inside will be positioned in front of the RecyclerView which would work in some scenarios but is a very sloppy workaround and won't work in scenario 2.
I haven't found anything that has encountered this same scenario which explains how but I think have seen this same behavior in various apps.
Any help would be greatly appreciated! Thank you!
Regards,

Soft keyboard changes from numerical to alphanumerical automatically on number type EditText

I have an EditText with input_type "number".
It lives inside a layout which is an item inside a ListView.
The problem is the following:
when I touch the EditText, I quickly get the soft numerical keyboard, but in less than a second it automatically changes to regular soft keyboard showing all letters. Obviously, I want the numerical keyboard.
To add more weirdness to the problem, if I change the layout_height of the ListView from match_parent to wrap_content, the problem doesn't occur. But unfortunately I need to keep the ListView with height match_parent.
Anyone has any ideas?
Thanks!
I could be wrong but you may want to consider changing your design by placing any edit text fields within a scrollview. The getView method of your list adapter gets called multiple times at unpredictable intervals that you will not be able to control. This will cause any init code you have in xml or code to be re initialized over and over again with some interesting results. If you have multiple elements in your list items that may be what is cause the keyboard to "work" when you adjust the height.

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?

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.

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.

Categories

Resources