Expand/open a spinner on click of another item/widget?
Asked Answered
V

2

14

I am trying to expand a Spinner when user click on another Button. as example : I have a Spinner with values and a 'OK' button when user click on 'ok' buttton without selecting any value from spinner, Spinner expands itself. Is this possible to get a event to expand spinner without user interaction on spinner.

Vannie answered 21/1, 2014 at 4:47 Comment(0)
I
57

Just call Spinner.performClick() to expand Spinner without user interaction...

    final Spinner spinner = (Spinner) findViewById(R.id.spinner);
    Button okButton = (Button) findViewById(R.id.yesButton);
    okButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if(spinner.getSelectedItem() == null) { // user selected nothing...
                spinner.performClick();
            }
        }
    });
Insolvency answered 21/1, 2014 at 4:55 Comment(0)
G
5

Put in your view.onClick

YourSpinner.PerformClick();
Gelderland answered 8/10, 2016 at 12:17 Comment(1)
YourSpinner.performClick();Wnw

© 2022 - 2024 — McMap. All rights reserved.