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.
Related
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
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 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.
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.