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

蹲街弑〆低调 提交于 2019-12-21 09:02:11

问题


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.


回答1:


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();
            }
        }
    });



回答2:


Put in your view.onClick

YourSpinner.PerformClick();


来源:https://stackoverflow.com/questions/21249380/expand-open-a-spinner-on-click-of-another-item-widget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!