'android spinner setfocus
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?
Solution 1:[1]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Venkatesh S |
