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

后端 未结 2 1405
夕颜
夕颜 2021-02-20 07:25

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 select

相关标签:
2条回答
  • 2021-02-20 07:43

    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();
                }
            }
        });
    
    0 讨论(0)
  • 2021-02-20 07:46

    Put in your view.onClick

    YourSpinner.PerformClick();
    
    0 讨论(0)
提交回复
热议问题