I have a ScrollView in which I have a quite long form, mainly using EditText elements. The problem is, that when the user scrolls around in this form, ScrollView changes the focus constantly. It seemed to me, that it assigns focus to the first element on screen when the user stops touching the screen, and the fling motion triggers.
How can I disable this?
Just a thought that you can make EditText as non-focusable elements. And when user will click on any item in ListView you can make that particular element focusable again.
Related
I've a ScrollView, inside that there are few views one of them is a TextView. I'm pragmatically setting current time to the TextView. Therefore TextView updates every second. Now when I over scroll ScrollView, the ScrollView moves to top. I guess its losing touch when TextView updates.
So how can I prevent ScrollView to move to top?
That's your friend:
android:descendantFocusability="blocksDescendants"
Set this attribute to the Elements INSIDE of the ScrollView.
But since this removes the focusability of the elements you won't be able to edit any inputs like EditText etc.
In this case you could "prevent" the ScrollView from scrolling to the current focus (it does not scroll "to the top") by ensuring the focus to be at the position I like.
To give an example:
I've got a ScrollView with a TableView inside and a CheckBox in each row of the table. When I check one of them, the color of the current row is to be changed. But: the moment I set the color, the ScrollView scrolls to the focus.
So I set the focus to the ckeckbox I just clicked before I change the color:
// enable focusability if necessary:
// cbOK.setFocusable(true);
// cbOK.setFocusableInTouchMode(true);
cbOK.requestFocus();
row.setBackgroundColor(....);
I have some edittexts in a scrollview. When a user clicks on them the keyboard shows up and sometimes it covers the edittext. The user can scroll the half of the screen that shows the page to the edittext but the minute the user types something it immediately scrolls to the top obscuring the edittext again.
How do I get this to stop?
Also for what it's worth the scrollview has
android:focusableInTouchMode="true"
in it's XML.
Set android:descendantFocusability="beforeDescendants" for scrollview and it should work!
Link1 :
Focusable EditText inside ListView
Link2 :
https://stackoverflow.com/a/2680077/1556997
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?
I have a listview and button in a scrollview. When i scroll both list and button loses focus. When i tap on button it did not work but next time i tap it works i think button loses focus and focus is towards scrollview how to handle this please help
Never put ListView inside a ScrollView. ListView handles scrolling, and wrapping it in a ScrollView can cause problems with focus, touch-events etc. If you want other Views added to the top or bottom of you list, simply use ListView.addHeaderView() or ListView.addFooterView()
Scroll view can have only one child, put your button and listview in common layout and try out.
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.