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