GithubHelp home page GithubHelp logo

jaredrummler / materialspinner Goto Github PK

View Code? Open in Web Editor NEW
1.3K 1.3K 220.0 718 KB

A spinner view for Android

License: Apache License 2.0

Java 100.00%
android android-library dropdown material-design popup-window spinner

materialspinner's Introduction

Entrepreneurial Software Engineer // Founder & CEO at GoatBytes.IO // Android Enthusiast

LinkedIn StackOverflow X (Twitter) GitHub GitHub User's stars

materialspinner's People

Contributors

cazador4 avatar hamdy-khader avatar jaredrummler avatar nkarasch avatar rafaruiz avatar zanechua avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

materialspinner's Issues

How to change item text size?

I see the item TextView is at ms__list_item.xml. And I do not find out where to set the item. Of course, I can set a new adapter to do this. But maybe a convenient method is better.
Thanks.

MaterialSpinnerAdapter skips position 2 and all the value displayed are (position + 1)

I created an Adapter which extends MaterialSpinnerAdapter. When item1 is selected, position = 1 but when item2 is selected, position = 3. So if January is selected, then January is displayed. But if February is selected then March is shown.

spinneritem2selected

spinneritem2

Consequently all other values displayed are selected item number + 1. Hence when last value is selected, the app crashes as now the index matches the array size (IllegalStateException). But getDropDownView works fine. It does not skip a value like getView/ getItem does. This can be seen that the app does not crash when December is shown.

spinneritemlast

But if I select December, it crashes (IllegalStateException).

public class EnglishSpinnerAdapter extends MaterialSpinnerAdapter {
    private List list;
    private Context ctx;

    public EnglishSpinnerAdapter(Context context, List items) {
        super(context, items);
        ctx = context;
        list = items;
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TextView textView = new TextView(ctx);
        textView.setTypeface(S.engFont);
        textView.setTextSize(18);
        textView.setGravity(Gravity.CENTER);
        textView.setTextColor(ContextCompat.getColor(ctx, R.color.black));
        textView.setText(list.get(position).toString());
        return textView;
    }

    @Override
    public View getDropDownView(int position, View convertView, ViewGroup parent) {
        TextView textView = new TextView(ctx);
        textView.setTypeface(S.engFont);
        textView.setTextSize(18);
        textView.setGravity(Gravity.CENTER);
        textView.setTextColor(ContextCompat.getColor(ctx, R.color.black));
        textView.setText(list.get(position).toString());
        return textView;
    }`

The declaration of the spinner:

        final MaterialSpinner msMonth = (MaterialSpinner) getActivity().findViewById(R.id.fgenderage_ms_month);
        List monthList = Arrays.asList(getResources().getStringArray(R.array.fgenderage_month));
        msMonth.setAdapter(new EnglishSpinnerAdapter(getActivity(), monthList));
        msMonth.setDropdownMaxHeight(S.dpToPx(getActivity(), 130));

Not working

It is not working, it gives

Rendering Problems The following classes could not be instantiated:
-ย com.jaredrummler.materialspinner.MaterialSpinner

error in the .xml file

pop-up

I am having this issue where if the material spinner is at the bottom of the screen the options are not getting displayed because their is no screen space. How do I make it "drop-up" / "pop-up"so that all my items are shown?
Thank you!

Getdropdownview displays nothing when MaterialSpinnerBaseAdapter is extended

I have tried to use the following code:

public class EnglishSpinnerAdapter extends MaterialSpinnerBaseAdapter {
private List list;
private Context ctx;

public EnglishSpinnerAdapter(Context context, List items) {
    super(context);
    ctx = context;
    list = items;
}

@Override
public Object getItem(int position) {
    return list.get(position);
}

@Override
public int getCount() {
    return list.size();
}

@Override
public Object get(int position) {
    return list.get(position);
}

@Override
public List getItems() {
    return list;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    TextView textView = new TextView(ctx);
    textView.setTypeface(S.engFont);
    textView.setTextSize(18);
    textView.setGravity(Gravity.CENTER);
    textView.setTextColor(ContextCompat.getColor(ctx, R.color.black));
    textView.setText(list.get(position).toString());
    return textView;
}

@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
    TextView textView = new TextView(ctx);
    textView.setTypeface(S.engFont);
    textView.setTextSize(18);
    textView.setGravity(Gravity.CENTER);
    textView.setTextColor(ContextCompat.getColor(ctx, R.color.black));
    textView.setText(list.get(position).toString());
    return textView;
}

}`

I get this output. Get drop down view is blank. But if I select an item, it gets displayed properly. So if I selected the place where February should have been displayed, I get February as the output. So the issue is in just the rendering of the view.

spinnergetdropdownview

Not working with SimpleCursorAdapter

Hello, this lib not working with SimpleCursorAdapter? :/
image

image

MaterialSpinner materialSpinner = (MaterialSpinner) view.findViewById(R.id.sp_edit_state);

        SqliteHelper db = new SqliteHelper(getContext());
        Cursor c = db.getStates();

        SimpleCursorAdapter adapter = new SimpleCursorAdapter(getContext(),
                android.R.layout.simple_list_item_1,
                c,
                new String[] {"name"},
                new int[] {android.R.id.text1}, 0);
        materialSpinner.setAdapter(adapter);

This cursor is working fine, i replace to android spinner and showed my results normaly.

Set scroll postion

Hi. I'd like to provide the user with the functionality to memorize what they have clicked. After clicked I will pop the selected item to the first position. And I'd like to know how to set my scroll bar to the top after user clicked.
Thanks.

MaterialSpinnerBase adapter.getCount() on a null object reference.

java.lang.NullPointerException: Attempt to invoke virtual method 'int com.jaredrummler.materialspinner.MaterialSpinnerBaseAdapter.getCount()' on a null object reference
at com.jaredrummler.materialspinner.MaterialSpinner.calculatePopupWindowHeight(MaterialSpinner.java:442)
at com.jaredrummler.materialspinner.MaterialSpinner.onMeasure(MaterialSpinner.java:191)

get item by index number

Hi there
let's assume I have following code:

    spinner = (MaterialSpinner) findViewById(R.id.spinner);
    spinner.setItems("Canada", "Germany", "France", "Netherlands", "United Kingdom", "United States");

how can I get items by index number?

How to make the dropdown animate?

So this is cool an all ๐Ÿ‘ , but I was wondering if it was possible to animate the spinner, like when the user clicks on it, the ripple shows up. And when the dropdown comes down, it does so with an animation. Is this possible? Your gif shows it is, but yet it doesn't work :(

Unable to delete the items in the spinner control

Hi,

I am unable to find method to remove all the items from the spinner control. I have two spinner controls and second spinner will be populated based on first spinner control option selected by user. So i have to clear all the existing items and populate with new items.

Please provide solution to remove the items from the spinner control.

Tint color

I know this may not be an issue but more like a suggestion.
I have this orange background when I click on the item selected. Does anyone maybe know why? Could I change this to some ripple effect with custom color?

Thanks.

Selected item

on activity created it does not give selected item while after click on spinner and after selecting any value it works fine,but what if i want result on first activity created.

Some rows are hidden on the first run!

My XML looks like this

        <com.jaredrummler.materialspinner.MaterialSpinner
                android:id="@+id/sp_invoice_prepared_by"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.46"
                android:textSize="@dimen/_15sdp" />

My values are set like this

 String[] InvoiceTaxMethod = new String[]{"STANDARD", "NO-TAX", "SIMPLE"};

On the first run view is showing the with out STANDARD

first

After just opening the Spinner and selecting the same value NO-TAX.. NOW STANDARD is appearing

second

Have I missing anything? Please help?

Thanks.
Srinath Rao

Selecting the first item programmatically

How do you select the first item in the spinner?

I tried doing the following,

spinner.setOnItemListeners(..){ ... };

spinner.setSelectedIndex(2);
spinner.setSelected(true);

but it doesn't seem to be working.

Thanks!

Dropdown height

Hello, can you please add a dropdown max dropdown height? I have too much items in the spinner and it goes all the way down to the screen. Thanks!

Unresposive and slow UI ?

im using this library in fragment but why it make the UI become slow or unresponsive for some second ?

here my code :
`
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.jaredrummler.materialspinner.MaterialSpinner
    android:id="@+id/spinner"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

</android.support.constraint.ConstraintLayout>`

and my fragment code :

` @OverRide
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

    rootView = inflater.inflate(R.layout.d, container, false);
    this.container = container;

    MaterialSpinner spinner = (MaterialSpinner) rootView.findViewById(R.id.spinner);
    spinner.setItems("Ice Cream Sandwich", "Jelly Bean", "KitKat", "Lollipop", "Marshmallow");
    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();
        }
    });

    return rootView;
}`

and here the error in logcat with "No Filter" selected :
03-30 08:59:49.657 1582-1753/system_process W/AudioTrack: AUDIO_OUTPUT_FLAG_FAST denied by client 03-30 08:59:58.262 18897-18897/navotera.syasep W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed.
thanks u

Unable to compile with Android

It says "Failed to resolve: com.jaredrummler:material-spinner:1.1.0", it was working just a while back, hosted server down?

Disable view

Hi!
How to disable MaterialSpinner for prevent that user change the selected value?
I tried:

<com.jaredrummler.materialspinner.MaterialSpinner
                ...
                android:enabled="false"
                android:clickable="false"
                android:focusable="false"
                android:focusableInTouchMode="false"/>

But PopupWindow continues to show.

Add Readme

Add Readme
Add Photo(Bonus points for .gif)

Hide scrollbar in DropDown menu

Hello! I want to hide the ListView's scrollbar. I had modify the code, but I don't have the authority to commit. Would you modify the code, please. Thanks.

Drop Down Items of spinner

Drop down spinner items can not visible.when click on spinner list of items are open but the items name not visible.how it visible to drop down list.

Avoid spinner wrapping text

Hello, I really like your library, I just have a small issue with it. How can I avoid the spinner drop-down wrapping text and putting ellipses when there's plenty of space?

Display of item in the space between spinner and dropdown

This is a minor issue but I am just bringing it to your notice. As you can see in the screen shot, little bit of January is displayed in the lavender space (margin?) between the spinner and dropdown. Either the space can be eliminated or let it have the same background as the dropdown view.

Thanks

spinnerspace

Accessing Adapter for notify data changed

When I was using this awesome lib I couldn't update the data in runtime
I could only by using setItems and I needed to remove item and update the list for next use but I couldn't do this
Please provide us notify data change that I can found in the adapter

Set each item text color

Hi, is there a way to set each item text a specific color? Like item 1 orange, item 2 blue, item 3 pink, etc. Thanks.

can you make it so im able to hide the arrow from code ?

Right now we can only change the arrow visiblity from code using ms_hide_arrow. Can you put make it configurable from code. So specifically i mean the variable hideArrow. can you make a getter and setter for it so its exposed ?

Unable to add window

Something weird is happening here. I have added the MaterialSpinner to a PopupWindow. The popup window shows the MaterialSpinner but when I touch it, the app force closes with this error:

MaterialSpinner spinnerCategory = (MaterialSpinner) view.findViewById(R.id.spinner);
spinner.setItems("Jelly Bean", "KitKat", "Lollipop", "Marshmallow");
android.view.WindowManager$BadTokenException: Unable to add window -- token android.view.ViewRootImpl$W@2493a9d is not valid; is your activity running?
  at android.view.ViewRootImpl.setView(ViewRootImpl.java:562)
  at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:282)
  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
  at android.widget.PopupWindow.invokePopup(PopupWindow.java:1104)
  at android.widget.PopupWindow.showAtLocation(PopupWindow.java:933)
  at android.widget.PopupWindow.showAtLocation(PopupWindow.java:897)
  at com.jaredrummler.materialspinner.MaterialSpinner.expand(MaterialSpinner.java:404)
  at com.jaredrummler.materialspinner.MaterialSpinner.onTouchEvent(MaterialSpinner.java:199)
  at android.view.View.dispatchTouchEvent(View.java:8471)
  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
  at android.view.View.dispatchPointerEvent(View.java:8666)
  at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4123)
  at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3989)
  at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3544)
  at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3597)
  at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3563)
  at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3680)
  at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3571)
  at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3737)
  at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3544)
  at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3597)
  at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3563)
  at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3571)
  at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3544)
  at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5807)
  at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5781)
  at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5752)
  at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5897)
  at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
  at android.os.MessageQueue.nativePollOnce(Native Method)
  at android.os.MessageQueue.next(MessageQueue.java:143)
  at android.os.Looper.loop(Looper.java:122)
  at android.app.ActivityThread.main(ActivityThread.java:5258)
  at java.lang.reflect.Method.invoke(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:372)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

Note: I haven't added any listeners yet. I don't know why this is happening. The MaterialSpinner view is added in a layout and that layout is inflated and used by a PopupWindow.

Spinner is not visible on API < 21 when it's placed inside toolbar

I can click on spinner and dropdown menu shows perfectly. But... it's not visible :/
xml code:

<android.support.v7.widget.Toolbar
                    android:id="@+id/sort_toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    app:layout_scrollFlags="scroll|enterAlways">

                    <com.jaredrummler.materialspinner.MaterialSpinner
                        android:id="@+id/spinner"
                        android:layout_width="match_parent"
                        android:textColorHint="@color/black"
                        android:layout_height="wrap_content"
                        android:layout_marginRight="10dp"
                        android:layout_marginEnd="10dp" />

                </android.support.v7.widget.Toolbar>

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.