Entrepreneurial Software Engineer // Founder & CEO at GoatBytes.IO // Android Enthusiast
jaredrummler / materialspinner Goto Github PK
View Code? Open in Web Editor NEWA spinner view for Android
License: Apache License 2.0
A spinner view for Android
License: Apache License 2.0
Entrepreneurial Software Engineer // Founder & CEO at GoatBytes.IO // Android Enthusiast
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.
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.
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.
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));
If you put multiple MaterialSpinner in a ScrollView, you will select the drop-down shadow
It is not working, it gives
Rendering Problems The following classes could not be instantiated:
-ย com.jaredrummler.materialspinner.MaterialSpinner
error in the .xml file
How we can select nothing for initializing the widget to make user select something instead of default element of spinner?
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!
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.
Hello, this lib not working with SimpleCursorAdapter? :/
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.
How can I put a text hint when the spinner doesnt have selected an item
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.
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)
How to confuse or need???
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?
dimen name="ms__padding_left">24dp</dimen
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 :(
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.
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.
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.
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
After just opening the Spinner and selecting the same value NO-TAX.. NOW STANDARD is appearing
Have I missing anything? Please help?
Thanks.
Srinath Rao
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!
How to set spinner edges as rounded ?
Material Spinner not woking on Android 7
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!
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
It says "Failed to resolve: com.jaredrummler:material-spinner:1.1.0", it was working just a while back, hosted server down?
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.
Hi bro.
this is an awesome lib. can u add hint feature to spinner?
sometimes its better than the default selection
Add Readme
Add Photo(Bonus points for .gif)
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 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.
I can't add default item in spinner ? Please tell me how to do this ?
Is there any option to set a selector drawable for the inside listview.
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?
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
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.
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 ?
How do i can use this lib in fragment ..
There ; it gives me NullPointerException
what do i can do ?
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
.
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>
I have implemented betterspinner in my project.
In one screen spinner is at the bottom of the screen
when I click on spinner dropdown is displaying at bottom I want to display it above spinner view same as Spinner for android .
Pls help
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.