Expand/open a spinner on click of another item/wid

2020-07-06 05:46发布

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.

2条回答
手持菜刀,她持情操
2楼-- · 2020-07-06 06:03

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();
            }
        }
    });
查看更多
乱世女痞
3楼-- · 2020-07-06 06:04

Put in your view.onClick

YourSpinner.PerformClick();
查看更多
登录 后发表回答