This question seems to be asked so many times but after trying over 20 different ideas I still have an issue.
I have an inflated dialog that consists of (from the top) 7 spinners followed by several edittext's.
Spinners and edittext are on separate linearlayouts.
When the dialog is created the focus goes to the first edittext and as this is some way down the dialog, the first spinner is scrolled out of view.
What I require is a way to make the first spinner focused or the scroll to be upper most.
What have I done?
Well I have set:
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
to stop the soft keyboard from displaying (which works)
manufacturer = (Spinner) entryView.findViewById(R.id.myyarns_add_dialog_manufacturer_spinner);
manufacturer.setFocusable(true);
manufacturer.setFocusableInTouchMode(true);
manufacturer.requestFocus();
This has no effect either in onPrepareDialog or in onCreateDialog
Then I tried setting
weight = (EditText) entryView.findViewById(R.id.myyarns_add_dialog_weight);
weight.clearFocus();
where weight is the id of the first edittext which gets the focus - still weight gets the focus
Then I tried scrolling the dialog view to the top but that doesnt do anything
ScrollView scroller = (ScrollView) entryView.findViewById(R.id.myyarns_scroll);
scroller.scrollTo(0, 0);
Anything else I can do?
For all your editText in xml set android:focusable="false"
For your first spinner set android:focusable="true"
or
programmatically set focus to field which you required
Related
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?
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 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.
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.
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.