Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
336 views
in Technique[技术] by (71.8m points)

android - multiple spinner's simple doubts

Im new to android. i have tried to built an application which has 2 spinner... i have few doubts to clear before going deep to my application..

please give brief answer to my question...

  1. is it possible to have 2 spinners in one view?
  2. can i add setOnItemSelectedListener(this) for both?
  3. if yes, how could i know which option is selected on both the spinners? like spinner.getSelectedItemPosition(); on both the spinners?

waiting for ur valuable replies. reference materials are also appreciable

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Yes, you can have multiple spinner's that can be managed by single listener or you can have seperate Listener for each.

For Single Listener you can do something like this,

Set the Listener

spinner1.setOnItemSelectedListener(this);
spinner2.setOnItemSelectedListener(this);

Then you can use onItemSelected to get perform the action related to the spinner's.

    @Override
        public void onItemSelected(AdapterView<?> parent, View view,
                                                      int position,long arg3) 
        {
        int id = parent.getId();
        switch (id) 
        {
                case R.id.spinner1:
                // your stuff here
                break;
            case R.id.spinner2:
               // your stuff here
            break;
        }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...