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?
Related
I'm using a RecyclerView with list items that contain an EditText control with the android:imeOptions set to actionNext. When I tap the actionNext button on the on-screen keyboard the focus goes to the EditText control of the next list item as expected. If the focus is on the EditText of the last list item that is visible on the screen then the RecyclerView creates the next list item and its EditText control receives the focus as I would expect.
The problem I have is with what happens when I tap the actionNext button when the EditText control of the last list item of the entire collection of data items has the focus. I would like the RecyclerView to scroll to the top and set the focus on the EditText control of the list item which shows the first item of the data item collection, but the focus actually goes to the EditText control of the first list item that is visible.
For example if I have 8 items in my collection and only the last 5 items fit on the screen, when I tap the actionNext button on the EditText control of the last item, the focus goes to the EditText control of the 4th item instead of the 1st item as I'd like.
I tried to achieve this behavior using an OnKeyListener on the EditText control but it won't fire when I tap the actionNext button. Could someone point me in the right direction?
I have a pretty big ScrollView that consists of EditTexts and Spinners.
I have a huge problem with EditText focus that has been driving me nuts for the last 2 days. The issue is:
After editing an EditText, press 'back' to close the keyboard (the EditText) still remains focused, so when I scroll down to a Spinner and pick an item, the ScrollView jumps back to the last focused EditText, which is very annoying.
I've looked all over StackOverflow and tried everything. I've tried clearFocus() on the EditText after editing, but the focus just jumps to another EditText. I put android:focusableInTouchMode="true" and android:focusable="true"on the parent LinearLayout, hoping that it would steal the focus. Still doesn't work.
I have tried setting click listeners on spinners, and calling requestFocus() when clicking them. Nothing works.
Please help.
I'm having an issue with a listview.
It's displaying items with a checkbox on the right.
When I enables the fastscrolling, everytime I press on the checkbox, the fastscrollbar appears and it scrolls to the position I pressed rather than just checking the checkbox...
If it matters I enable the fastscrollbar dynamically depending on the number of items in the list.
How can I fix this focus issue ?
Edit: In fact I'm also having the same issue without a checkbox. When I press on the right of the listview item, it doesn't open the item like it should but it scrolls to the position I pressed. Same behavior in a GridView...
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
I have a ListView with custom adapter. In each row there is a checkbox and couple of textviews. I want user to give option to delete the check marked items, so as soon as soon clicks on one of the checkbox, I want a button bar to slide in from the bottom and stay at the bottom regardless of listview scroll. This is something like the email app behavior of Motorola Cliq and to some extent gmail app itself.
I have tried adding a relativelayout (containing buttons) below the listview, which has visibility set to gone initially, but as soon as user checks a button, the visibility changes to "visible". I have added a slide-in animation to it too. It is working but problem is that it is overlapping the last element of the listview which user can not checkmark if the button bar has already become visible. So I tried to set the bottom margin of the listview equal to the height of the button bar when I'm changing the button bar visibility, which solves the problem of overlap, but now the checkbox behavior has gone weird. Clicking on one checkmark tries to checkmark another checkmark in the list for some weird reason. I noticed that this happens because as soon as I change the listview margin, list redraws itself, and during this new call to getView() method of adapter, things mess up.
I wanted to ask if anyone has done something like this. What is the best method to add such button bar below list while keeping the slide-in animation intact. Also, What is the footer-view of listview and can that solve my problem?