lesilva / betterspinner Goto Github PK
View Code? Open in Web Editor NEWA library creates spinners for Android that really work
A library creates spinners for Android that really work
It just gives out of bound index exception when I try using setSelected(index) method.
there is no method to capture the text selection
I added a listener to setOnItemSelectedListener, but those methods never get called:
PaddedStringArrayAdapter deptAdapter = new PaddedStringArrayAdapter(getActivity(),
android.R.layout.simple_spinner_item, getDepartmentNames());
deptAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
MaterialBetterSpinner deptSpinner = (MaterialBetterSpinner) view.findViewById(R.id.deptSpinner);
deptSpinner.setAdapter(deptAdapter);
deptSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(parent.getContext(), "onItemSelected", Toast.LENGTH_SHORT).show();
Log.d("Console", "item selected");
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
Log.d("Console", "nothing selected");
}
});
I also tried the setOnItemClickListener, but then the spinner takes a double tap to open, which is definitely not desirable.
deptSpinner.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//Toast.makeText(parent.getContext(), "onItemSelected", Toast.LENGTH_SHORT).show();
Log.d("Console", "item selected");
}
});
Thank you and I look forward to your reply.
Hey!
I have the following issue like explained here:
#11
You said something about modify the java file and add it to your project. I don't know if did it correctly, but I think not because I get a java.lang.ClassCastException. I added the "MaterialBetterSpinner.java" to my project. Then I used in my Activity "import de.myprojects.utils.MaterialBetterSpinner".
This is how I actually added your library to my project (using Android Studio):
compile ('com.weiwangcn.betterspinner:library-material:1.1.0') {
exclude group: 'com.android.support', module: 'appcompat-v7'
exclude group: 'com.android.support', module: 'appcompat-v7'
}
Would be appreciate it, when you can explain me how I can add the files to my project, that I'm able to modify them.
Thanks!
I am getting following error while trying to sync my gradle file after adding following line to my gradle file
compile ('com.weiwangcn.betterspinner:library-material:1.1.0') {
exclude group: 'com.android.support', module: 'appcompat-v7'
exclude group: 'com.rengwuxian.materialedittext', module: 'library'
}
Error:
C:\android\MyProjectsAndStud\Twigly\app\build.gradle
Error:(48, 14) Failed to resolve: com.weiwangcn.betterspinner:library-material:1.1.0
Show in File
Show in Project Structure dialog
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Filter.filter(java.lang.CharSequence, android.widget.Filter$FilterListener)' on a null object reference at android.widget.AutoCompleteTextView.performFiltering(AutoCompleteTextView.java:861) at com.weiwangcn.betterspinner.library.material.MaterialBetterSpinner.onFocusChanged(MaterialBetterSpinner.java:49) at android.view.View.handleFocusGainInternal(View.java:4962) at android.view.View.requestFocusNoSearch(View.java:7678) at android.view.View.requestFocus(View.java:7657) at android.support.v4.widget.NestedScrollView.onRequestFocusInDescendants(NestedScrollView.java:1597) at android.view.ViewGroup.requestFocus(ViewGroup.java:2603) at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:2644) at android.view.ViewGroup.requestFocus(ViewGroup.java:2600) at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:2644) at android.view.ViewGroup.requestFocus(ViewGroup.java:2600) at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:2644) at android.view.ViewGroup.requestFocus(ViewGroup.java:2600) at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:2644) at android.view.ViewGroup.requestFocus(ViewGroup.java:2600) at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:2644) at android.view.ViewGroup.requestFocus(ViewGroup.java:2600) at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:2644) at android.view.ViewGroup.requestFocus(ViewGroup.java:2600) at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:2644) at android.view.ViewGroup.requestFocus(ViewGroup.java:2600) at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:2644) at android.view.ViewGroup.requestFocus(ViewGroup.java:2603) at android.view.View.requestFocus(View.java:7624) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1927) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1061) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5885) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767) at android.view.Choreographer.doCallbacks(Choreographer.java:580) at android.view.Choreographer.doFrame(Choreographer.java:550) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5254) 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)
找不出来是为啥
How can i reset Spinner to default ?
How can i set Default item selected programmatically after initializing adapter?
spinner.setSelection(0); doesn't work
If spinner has requested focus and now you touch screen but not else view, onFocusChanged() will doesn't work, and the variable isPopup is still true. Now you need to double click to make spinner showDropDown().
Is there a way to wrap content of drop down menu with a width larger than the size of spinner?
I have iserted in my grandle this
compile ('com.weiwangcn.betterspinner:library-material:1.1.0') {
exclude group: 'com.android.support', module: 'appcompat-v7'
exclude group: 'com.rengwuxian.materialedittext', module: 'library'
}
and
in my layout this:
...
...
...
<com.weiwangcn.betterspinner.library.material.MaterialBetterSpinner
android:id="@+id/spinner2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="MaterialBetterSpinner"
app:met_floatingLabel="normal" />
but the compiler report me:
Error:(43) No resource identifier found for attribute 'met_floatingLabel' in package 'com.bandweb.myviewrecipes'
why?
Thanks.
Error:Execution failed for task ':app:processDebugManifest'.
Manifest merger failed : Attribute application@allowBackup value=(false) from AndroidManifest.xml:47:9
is also present at com.weiwangcn.betterspinner:library-material:1.1.0:12:9 value=(true)
Suggestion: add 'tools:replace="android:allowBackup"' to element at AndroidManifest.xml:40:5 to override
xml
<BetterSpinner
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_weight="1"
android:id="@+id/payment_methods"
android:text="Select Payment Methods" />
Java
BetterSpinner spinner = (BetterSpinner) findViewById(R.id.payment_methods);
Gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.wdullaer:materialdatetimepicker:2.2.0'
compile ('com.weiwangcn.betterspinner:library-material:1.1.0') {
exclude group: 'com.android.support', module: 'appcompat-v7'
exclude group: 'com.rengwuxian.materialedittext', module: 'library'
}
}
Even adding
import com.weiwangcn.betterspinner.library.BetterSpinner;
import com.weiwangcn.betterspinner.library.material.MaterialBetterSpinner;
does not solve my problem.
Found this today, will look into it later.
Hello,
The following problem is really annoying.
While opening de xml to edit the layout files which contains
<com.weiwangcn.betterspinner.library.material.MaterialBetterSpinner
It gives to following rendering problems. After you close the rendering problems. Whenever you change something in xml it will again throws this rendering problem again. So basically it waste my time.
Are there any chance for you to add View.isineditmode in your code?
Btw, while running the application, I don't have any problem. It is just about the designing phase.
Rendering Problems The following classes could not be instantiated:
- com.weiwangcn.betterspinner.library.material.MaterialBetterSpinner (Open Class, Show Exception, Clear Cache)
Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE Exception Details java.lang.AssertionError at android.content.res.BridgeResources.getDimensionPixelSize(BridgeResources.java:545) at com.rengwuxian.materialedittext.MaterialAutoCompleteTextView.init(MaterialAutoCompleteTextView.java:330) at com.rengwuxian.materialedittext.MaterialAutoCompleteTextView.(MaterialAutoCompleteTextView.java:316) at com.weiwangcn.betterspinner.library.material.MaterialBetterSpinner.(MaterialBetterSpinner.java:30) at java.lang.reflect.Constructor.newInstance(Constructor.java:422) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:835) at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70) at android.view.LayoutInflater.rInflate(LayoutInflater.java:811) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:838) at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70) at android.view.LayoutInflater.rInflate(LayoutInflater.java:811) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:838) at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70) at android.view.LayoutInflater.rInflate(LayoutInflater.java:811) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) at android.view.LayoutInflater.inflate(LayoutInflater.java:515) at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
Please update MaterialEditText to latest, and is anyway to use setSelection like Spinner ?
I try to use setSelection, but show error...
java.lang.IndexOutOfBoundsException: setSpan (1 ... 1) ends beyond length 0
How can I add a border to the spinner? stroke 1dp.
I want to change the color the divider... how to do ??
What about adding a dropdown indicator like the default spinner?
I need to set an item selected, but how doesn't exist setSelection I tried to use setText, but when I did this, the other options in spinner disappears, somebody knows what's going on?
when spinner loses focus then requires 2 taps to open list.
I found some similar closed issues but no solution.
thank you!
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Filter.filter(java.lang.CharSequence, android.widget.Filter$FilterListener)' on a null object reference
at android.widget.AutoCompleteTextView.performFiltering(AutoCompleteTextView.java:871)
at com.weiwangcn.betterspinner.library.material.MaterialBetterSpinner.onFocusChanged(MaterialBetterSpinner.java:49)
at android.view.View.handleFocusGainInternal(View.java:5347)
at android.view.View.requestFocusNoSearch(View.java:8080)
at android.view.View.requestFocus(View.java:8059)
at android.view.View.requestFocus(View.java:8026)
at android.view.View.requestFocus(View.java:8005)
at com.weiwangcn.betterspinner.library.material.MaterialBetterSpinner.onTouchEvent(MaterialBetterSpinner.java:74)
at android.view.View.dispatchTouchEvent(View.java:8920)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2684)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2400)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2684)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2400)
at android.widget.ScrollView.dispatchTouchEvent(ScrollView.java:610)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2684)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2400)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2684)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2400)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2684)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2400)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2684)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2400)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2684)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2400)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2552)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1767)
at android.app.Activity.dispatchTouchEvent(Activity.java:2840)
at android.support.v7.internal.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:59)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2513)
at android.view.View.dispatchPointerEvent(View.java:9125)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4632)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4470)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4020)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4073)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4039)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4153)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4047)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4210)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4020)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4073)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4039)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4047)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4020)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6480)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6379)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6350)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6570)
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
I have followed all your instructions, even make focusable to false in xml to prevent from getting exception, but when I touch spinner I am not getting anything, except getting above message in logcat.
How do i get the position of the selected item in spinner..?
dear Lesilva ,
the framwork is easy to use ,and it looks beautiful ....
but if it did not setAdapter ,the app crash..
someTimes we need to get data from the website ,
so ... will you update it ??
Hi how do you change the right drawable?
setCompoundDrawablesWithIntrinsicBounds(0,0,R.drawable.my_drawable,0) doesn't seem to work.
Thanks
嗨,我用了这个jar,但是,在spinner一上来的时候,我是没有数据的,然后动态加载,怎么实现,我这边一致都只有一个item!求解
hi i use better spinner with custom adapter all works fine for me
List<Employe> src= DBAdapter.getAllEmploye();
Employe[] values = src.toArray(new Employe[src.size()]);
adapter_emp = new SpinnerAdapter_emp(this, android.R.layout.simple_spinner_item,values);
BetterSpinner textView = (BetterSpinner)
findViewById(R.id.txtresps);
BetterSpinner textView1 = (BetterSpinner)
findViewById(R.id.txtrespr);
textView.setAdapter(adapter_emp);
but when i select an item from the spinner .The spinner display me com.example.....model.employe
which is the name of my class displayed in the spinner
what's wrong please?
how to change spinner menu list item fonts?
I just changed spinner selected item text by:
app:ms_typeface="fonts/custom.ttf"
hi all,
i have to set floating label center
I have problems in "MaterialBetterSpinner" to touch the first time.
When the focus is on another component and then touched on Spinner, the popup does not open the first time, you need to touching two more times.
I believe the problem is the call of performFiltering()
. https://github.com/Lesilva/BetterSpinner/blob/master/library-material/src/main/java/com/weiwangcn/betterspinner/library/material/MaterialBetterSpinner.java#L49
What is the reason for this call?
下拉列表选中如何监听?setOnItemSelectedListener没有作用
I want the spinner to disabled until a certain action is fulfilled
setEnabled(false) does not work
Please answer me for this as i imported the project rather than copy paste it. So it's hard to analyze a piece of code.
I try to set selected item index but with existing method "setSelection" nothing happened.
Hi, thanks for the library. Its great, I just had one query.
When you first click on the spinner it shows the items, but if the user clicks on back button to hide it without selecting to view the options later. Then the user will have to tap once and then twice for the items to show up again.
It also happens at times when you have selected an item already and want to change it, then the spinner will have to be clicked on twice to show up the items.
Please implement OnSelectedItem if you want it is better than default Spinner.
I love this plugin just cant seem to find a way to change the down arrow color.
How can I change the width of list item box or is there any way I can convert it into dialog box as in default spinner? Also is there any way I can customize the dark theme of list box into light one?
Hi
This Library has multi select for spinner?
Thank You
I want to set something like "CHOICE_MODE_MULTIPLE".
thank you very much for your effort and for this great library.
I'm trying to customize the view, but my default theme doesn't apply
<com.weiwangcn.betterspinner.library.material.MaterialBetterSpinner
android:id="@+id/item_type"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/item_type_hint"
app:met_floatingLabel="normal"
android:layout_marginTop="16dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginBottom="4dp" />
None of margins or textColors or other customizations are working.
How can I do that?
Ty,
Hi Lesilva,
First of all thanks for the awesome library...It will be great if design support library is used for edittext instead of rengwuxian.materialedittext because it indirectly imports rengwuxian.materialedittext library even though design support library is used...
Hi,
I am trying to use
categorySpinner.setEnabled(false);
billSpinner.setEnabled(false);
still, it is clickable. Please check.
Thanks.
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.