Coder Social home page Coder Social logo

Comments (14)

iamkdblue avatar iamkdblue commented on August 18, 2024 3

categorySpinner.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@OverRide
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.d("kkkk",""+position);
}
});
setOnItemClickListener Solved My Problem

from betterspinner.

JamworksPro avatar JamworksPro commented on August 18, 2024 3

If you create a new List Adapter WITH AN EMPTY LIST the setOnItemSelectedListener will never be called. Add at least one item to the list BEFORE creating the the adapter for it

from betterspinner.

Lesilva avatar Lesilva commented on August 18, 2024

If you take a look at the code, I'm using OnItemClickListener in my code as well, so if you override it, it will break. The solution to your problem is just copy the java file over to you project and modify it as you want. For now, that's all I can think of.

from betterspinner.

azizj1 avatar azizj1 commented on August 18, 2024

Yea I ended up making a composite listener so it doesn't get overridden. I'll push my changes soon

from betterspinner.

sekharrockz avatar sekharrockz commented on August 18, 2024

Thanks.

from betterspinner.

BatshevaR avatar BatshevaR commented on August 18, 2024

I'm getting this same issue,
I sew it is unrecommended to use a OnItemClickListener
why not instead change your source code to use OnItemSelectedListener?
it would be helpful for everybody

from betterspinner.

bantyK avatar bantyK commented on August 18, 2024

In case of multiple spinners in a single layout, how to get the id of the selected spinner in onItemSelectedListener (parent.getId() always returns -1)

from betterspinner.

csangeeta avatar csangeeta commented on August 18, 2024

Hello,
I am getting same issue. onItemSelected not calling and it is not displaying on the spinner as text,
Find my code below.

ArrayAdapter dataAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, products);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
products_mod.setAdapter(dataAdapter);
products_mod.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@OverRide
public void onItemSelected(AdapterView adapterView, View view, int i, long l) { Log.d("onItemSelected ",""+i); } @OverRide public void onNothingSelected(AdapterView adapterView) {
}
});

from betterspinner.

thumb2thiefapp avatar thumb2thiefapp commented on August 18, 2024

@csangeeta try this code its may be help you !
products_mod.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@OverRide
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.d("kkkk",""+position);
}
});

from betterspinner.

gtl23 avatar gtl23 commented on August 18, 2024

@thumb2thiefapp setOnItemClickListener cannot be used with spinner, BTW i'm also having the same issue. I've implemented the spinner as stated by the official android documentation. In one of the files of my project it is working as expected but not in the the other files. All the implementations are correctly done as stated by the official documentation in all the files.

from betterspinner.

csangeeta avatar csangeeta commented on August 18, 2024

Thank you @thumb2thiefapp and @gtl23.

from betterspinner.

iamkdblue avatar iamkdblue commented on August 18, 2024

@csangeeta your welcome !

from betterspinner.

RandyBlythe0 avatar RandyBlythe0 commented on August 18, 2024

If you create a new List Adapter WITH AN EMPTY LIST the setOnItemSelectedListener will never be called. Add at least one item to the list BEFORE creating the the adapter for it

That solved my issue Thanks

from betterspinner.

TechLee2019 avatar TechLee2019 commented on August 18, 2024

This code will help you

ArrayAdapter adapter = new ArrayAdapter(getActivity(), android.R.layout.simple_list_item_1, items);

    m_ListView.setAdapter(adapter);
    m_ListView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            Log.v("item", (String) parent.getItemAtPosition(position));
            Toast.makeText(getActivity(), (String) parent.getItemAtPosition(position), Toast.LENGTH_LONG).show();
            Toast.makeText(getActivity(), "working", Toast.LENGTH_LONG).show();

            if (position == 1) {
                Intent intent = new Intent(getContext(), CategoriesActivity.class);
                startActivity(intent);
            }

// ((TextView) parent.getChildAt(0)).setTextColor(Color.WHITE);
}
@OverRide
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
Log.v("item", (String) parent.getItemAtPosition(0));
}
});

from betterspinner.

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.