Android - how to keep an AutoCompleteTextView from keeping focus - android

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.

Related

Lock Focus inside a ListView on a TV Layout

I'm trying to find a way to lock the user inside a ListView (When using the D-Pad) preventing it from losing focus, allowing the user to navigate only through the ListView until "exit" is explicitly called.
There's any easy way to do this?
Found!
If you need this, it will be enough to set those parameters in xml:
android:id="#+id/myListView"
android:nextFocusDown="#id/myListView"
android:nextFocusForward="#id/myListView"
android:nextFocusLeft="#id/myListView"
android:nextFocusRight="#id/myListView"
android:nextFocusUp="#id/myListView"
Of course myListView is just an example id, and you could use this technique with any kind of View, it locks the focus setting the next focus to itself, in any direction.
The user is then locked inside that view until the view disappears or the focus is programmatically moved to another view.

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?

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.

Change layout when soft keyboard is shown

I would like to change the layout when an EditText is clicked and the softkeyboard is shown, so all EditText views are still visible.
I know that you can use the following two, but this is not what i'm looking for.
android:windowSoftInputMode="stateUnchanged|adjustPan">
android:windowSoftInputMode="stateUnchanged|adjustResize">
I've got 8 EditText views spread over the whole screen. When one is clicked to change a value I would like to still see all the ET views but nicely arrange and not pushed in a weird view.
Is there an easy way to do this?
I think you are going to have to do this yourself, but one technique might be ...
Create a layout with the views arranged for the keyboard shown (for instance a new RelativeLayout) that overlays your standard layout. Set it's visibility to GONE. Then when you detect the event that shows the keyboard hide the current view and show the alternate one
I suppose you could also use a ViewSwitcher
If you are using both at the same time then it doesnt work.Set the attribute android:windowSoftInputMode="adjustPan" only.That should work.

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