Android: problems with getSelectedItem on a spinner

后端 未结 6 1541
旧时难觅i
旧时难觅i 2021-01-27 00:35

I have a Spinner, and put the selected item in the body of a mail. this is my code:

@Override
protected void onCreate(Bundle savedInstanceState) {
         


        
6条回答
  •  一整个雨季
    2021-01-27 00:52

    Move the line

    final String taglia = spinnerTaglia.getSelectedItem().toString();
    

    to inside your OnClickListener

    Currently, you're trying to read the selected item before anything has been selected. You should also ensure that getSelectedItem() isn't returning null because, unless you enable / disable the btnCompilaOrdine button (when an item is selected), the user can press the button without selecting an item in the spinner.

提交回复
热议问题