Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 629
Manish Avatar asked Jan 21 '14 04:01

Manish


2 Answers

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();
            }
        }
    });
like image 54
Gopal Gopi Avatar answered Oct 15 '22 17:10

Gopal Gopi


Put in your view.onClick

YourSpinner.PerformClick();
like image 44
Fazal e Rasool Avatar answered Oct 15 '22 16:10

Fazal e Rasool