Coder Social home page Coder Social logo

Comments (7)

douglasjunior avatar douglasjunior commented on August 18, 2024 9

I dont know your need, but this library is a "Fake-spinner".

This library implement a EditText with AutoComplete. It looks like a spinner, works as spinner, but it's not a spinner.

Your items are strings. To know who is selected, simply retrieve the text that appears on the spinner, using the getText()

from betterspinner.

pcg92 avatar pcg92 commented on August 18, 2024 4

Then reneame this library to FakeSpinner and not betterSpinner

from betterspinner.

rubinnellikunnathu avatar rubinnellikunnathu commented on August 18, 2024 3

So, u r saying that this library is useless for my need. ?

from betterspinner.

douglasjunior avatar douglasjunior commented on August 18, 2024 1

Please, check #21. And to understand check #38.

from betterspinner.

harshithagb avatar harshithagb commented on August 18, 2024

You can get the item position using below listener:
material_spinner.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@OverRide
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {

        }
    });

from betterspinner.

douglasjunior avatar douglasjunior commented on August 18, 2024

@harshithagb be careful. This approach have a problem. If the item is selected programmatically, this event is not called.

from betterspinner.

tiansendev avatar tiansendev commented on August 18, 2024

Just add the listener of TextView.addTextChangedListener(new TextWatch(){...}) in the Constructer of your own Spinner which extends BetterSpinner/MaterialBetterSpinner, and in the callback method of void afterTextChanged(Editable s) you can get the position by mData.indexOf(getText()) and custom an callback function which involves the parm of "position". The sample code's as below:

public class CustomSpinner extends MaterialBetterSpinner {
    private OnItemSelectedListener l;
    private List<String> mData;
    public CustomSpinner(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                if (l != null && mData != null) {
                    l.onItemSelected(mData.indexOf(getText().toString()));
                }
            }
        });
    }

    public interface OnItemSelectedListener {
        void onItemSelected(int position);
    }

    public void setOnItemSelectedListener(OnItemSelectedListener l) {
        this.l = l;
    }

    /**attach data*/
    public void attachDataSource(List<String> data) {
        this.mData = data;
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(), R.layout.item_spinner_data, data);
        adapter.setDropDownViewResource(R.layout.item_spinner_data);
        this.setAdapter(adapter);
    }
}

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.