how to use selected values of spinner and number picker for if else statements

前端 未结 1 1468
渐次进展
渐次进展 2021-01-25 03:06

i want to use values of number picker and spinner together in a way that after selecting value of spinner and then number picker user enters search and this will stat another ac

相关标签:
1条回答
  • 2021-01-25 03:50

    It looks like you are looking for how to pass data between activities. First, you will have to make your NumberPicker global:

    private Spinner mSpinner;
    private NumberPicker mNumberPicker;
    

    With this in mind, you can send your data to a new Activity with an Intent like so:

    Intent intent = new Intent(v.getContent(), ListItem.class);
    intent.putExtra(ListItemActivity.EXTRA_MAJOR, mSpinner.getSelectedItem().toString());
    intent.putExtra(ListItemActivity.EXTRA_INT, mNumberPicker.getValue());
    startActivityForResult(intent, 0);
    

    Then you can receive the data in your new Activity with getIntent():

    public class ListItemActivity extends AppCompatActivity {
    
        public static final String EXTRA_MAJOR = "list_item:major";
        public static final String EXTRA_INT = "list_item:int";
    
        private int mInteger;
        private String mMajor;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_item);
    
            Intent intent = getIntent();
    
            mMajor = intent.getStringExtra(EXTRA_MAJOR);
            mInteger = intent.getIntExtra(EXTRA_INT);
        }
    
    }
    
    0 讨论(0)
提交回复
热议问题