GithubHelp home page GithubHelp logo

Comments (5)

jaredrummler avatar jaredrummler commented on May 31, 2024 4

You should just run whatever code is in your listener when you select the item. I don't know why this would be needed. If you really feel like this is necessary please provide an example.

from materialspinner.

jaredrummler avatar jaredrummler commented on May 31, 2024

spinner.setSelectedIndex(int) should select that item. Make sure you invoke this method after setting the items in the spinner. For example, if I set the selected index to 1 in the sample, then "Jelly Bean" would be selected instead of "Ice Cream Sandwich".

MaterialSpinner spinner = (MaterialSpinner) findViewById(R.id.spinner);
spinner.setItems("Ice Cream Sandwich", "Jelly Bean", "KitKat", "Lollipop", "Marshmallow");
spinner.setSelectedIndex(1); // <--- Set the item programmatically
spinner.setOnItemSelectedListener(new MaterialSpinner.OnItemSelectedListener<String>() {

  @Override public void onItemSelected(MaterialSpinner view, int position, long id, String item) {
    Snackbar.make(view, "Clicked " + item, Snackbar.LENGTH_LONG).show();
  }
});
spinner.setOnNothingSelectedListener(new MaterialSpinner.OnNothingSelectedListener() {

  @Override public void onNothingSelected(MaterialSpinner spinner) {
    Snackbar.make(spinner, "Nothing selected", Snackbar.LENGTH_LONG).show();
  }
});

from materialspinner.

jeffguo17 avatar jeffguo17 commented on May 31, 2024

The method setSelectedIndex just chooses the item to appear as the first item, but I would like to actually select the item as if it would call on onItemSelected.

Thanks again, very nice spinner!

from materialspinner.

tomridder avatar tomridder commented on May 31, 2024

what he means is that when he use spinner.setSelectedIndex(1);,it justchoose the item to appear as the first item,but it didn't execute the selected event.
I have the same problem,please fix that to make this project better.Thanks man.very nice Spinner!

from materialspinner.

ismail0234 avatar ismail0234 commented on May 31, 2024

+1

from materialspinner.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.