GithubHelp home page GithubHelp logo

Comments (10)

arcadefire avatar arcadefire commented on August 23, 2024 1

@pzienowicz sorry, I missed the previous message. I think the listener should be called when selecting the item programmatically. I'm adding this to my TODO list, or feel free to open a PR. :)

from nice-spinner.

ashish-d-hh avatar ashish-d-hh commented on August 23, 2024 1

To programatically select an option and call its click listener, I added this library as module to my project so that I can edit its file.

selectSiteSpinner.selectedIndex =0

    val fakeView = this.context?.let { FrameLayout(it) }
    selectSiteSpinner.onSpinnerItemSelectedListener.onItemSelected(
        selectSiteSpinner,
        selectSiteSpinner.adapter.getView(selectSiteSpinner.selectedIndex, null, fakeView),
        selectSiteSpinner.selectedIndex,
        selectSiteSpinner.adapter.getItemId(selectSiteSpinner.selectedIndex)
    )

from nice-spinner.

gisk4rd avatar gisk4rd commented on August 23, 2024

Is not a bug , unfurtunatelly is the base android behaviour

from nice-spinner.

arunavo4 avatar arunavo4 commented on August 23, 2024

Use AdapterView.OnItemSelectedListener instead of SimpleItemSelectedListener

Spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                    Log.d("Spinner",list.get(position));
                   //Do your thing here
                }

                @Override
                public void onNothingSelected(AdapterView<?> parent) {
                    Log.d("Spinner","Nothing Selected!");
                }
            });

from nice-spinner.

ideep avatar ideep commented on August 23, 2024

I have same problem but I already have used AdapterView & set selectedIndex to 0.
Still not working.
Tried Code:

 spinnerProperties.attachDataSource(propertyNamesList);
 spinnerProperties.setSelectedIndex(0);
 spinnerProperties.setSelected(true);
 spinnerProperties.setOnItemSelectedListener(onPropertyNameSelected);

 AdapterView.OnItemSelectedListener onPropertyNameSelected = new 
 AdapterView.OnItemSelectedListener() {
    @Override
    public void onItemSelected(AdapterView<?> adapterView, View view, int position, long l) {

        Log.d(TAG, "Selected Property: " + position);
    }

    @Override
    public void onNothingSelected(AdapterView<?> adapterView) {
    }
};

please help me to solve this issue @arcadefire

from nice-spinner.

arcadefire avatar arcadefire commented on August 23, 2024

Not sure what's the problem here.

from nice-spinner.

pzienowicz avatar pzienowicz commented on August 23, 2024

The problem is, that when we set selected index programmatically, OnItemSelectedListener is not called.
@arcadefire is it a normal behavior? How can I run listener when changed selected index in code?

from nice-spinner.

pzienowicz avatar pzienowicz commented on August 23, 2024

@arcadefire could you just let us know if this is normal behavior and we need to handle it by ourselves or just a bug?

from nice-spinner.

ashish-dhiman avatar ashish-dhiman commented on August 23, 2024
termsSpinner.setSelectedIndex(1); // set selection to any non required index
termsSpinner.getListView().performItemClick(termsSpinner.getListView().getChildAt(0), 0, termsSpinner.getListView().getAdapter().getItemId(0)); // 0 is the position we require to be clicked

from nice-spinner.

ashish-d-hh avatar ashish-d-hh commented on August 23, 2024

selectDivision.setText((selectDivisionSpinner.selectedItem as State).name)

We can get selected item from spinner and cast it accordingly, after that we can use its properties

from nice-spinner.

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.