Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A Spinner component with a floating label for Android, similar to EditText components wrapped in a TextInputLayout.

Moved to an Android library...

This Gist has been discontinued and will be updated on a GitHub project here. The files I have removed from this Gist can be found there. Please feel free to open issues, pull requests, etc, so that I can change and improve the library how you like.

If you are already using the Gist, delete the layout XML, values XML, and Java files (the ones I have removed from this Gist), and instead add the following in your app module's build.gradle dependencies:

compile 'com.satsuware.lib:usefulviews:+'

Make sure to change your imports as well in the files that you are using the LabelledSpinner component.

@paolorotolo

This comment has been minimized.

Copy link

paolorotolo commented Aug 12, 2015

Hey, awesome work!
I've found a typo.
Line 88:

        String labelText = a.getString(R.styleable.LabelledSpinner_labelText);

Should be:

        String labelText = typedArray.getString(R.styleable.LabelledSpinner_labelText);

Also, what about making an Android library?

@FarbodSalamat-Zadeh

This comment has been minimized.

Copy link
Owner Author

FarbodSalamat-Zadeh commented Sep 1, 2015

@paolorotolo Thank you. I have corrected the typo on line 88 now.

I think making an Android library for this would be a good idea, and I probably will in the near future.

@paolorotolo

This comment has been minimized.

Copy link

paolorotolo commented Sep 4, 2015

Cool, let me know if you need help. I've already some libraries in maven Central :)

@scottyab

This comment has been minimized.

Copy link

scottyab commented Nov 19, 2015

Thanks for this, it works well to show the hint. What would also be great is to show error text like the TextInputLayout. I might need that for current project, if so I'll see about contributing it back.

@mcelotti

This comment has been minimized.

Copy link

mcelotti commented Nov 30, 2015

This is a different solution to the same problem:
https://gist.github.com/smithaaron/d2acd57937d7a4201a79
With this you get also the error text (it extends AppCompatEditText)

@FarbodSalamat-Zadeh

This comment has been minimized.

Copy link
Owner Author

FarbodSalamat-Zadeh commented Dec 23, 2015

Apologies for the late reply, @scottyab - I have been working on making this an Android library.

Just to clarify, would you like the error text to be shown if the user makes an invalid selection (i.e. showing error text for specific selections)?

If so, in what way would you like it to be implemented? I have a suggestion below, but let me know if you have any other ideas:

int[] invalidSelectionIndices = {2, 4, 6, 7};
String errorText = "This is a sample error text";
labelledSpinner.setErrorSelection(invalidSelectionIndices, errorText);
@FarbodSalamat-Zadeh

This comment has been minimized.

Copy link
Owner Author

FarbodSalamat-Zadeh commented Dec 24, 2015

Moving to an Android library...

This Gist is now discontinued and will be updated on a GitHub project here (resolving @paolorotolo 's suggestion). Please feel free to open issues, pull requests, etc, so that I can change and improve the library how you like.

If you are already using the Gist, you do not need to make any major changes. Delete all of the files (above) that you have added (layout XML, values XML, and Java file), and instead add the following in your app module's build.gradle dependencies:

compile 'com.farbod.labelledspinner:labelledspinner:+'

Make sure to change your imports as well in the files that you are using the LabelledSpinner.

@FarbodSalamat-Zadeh

This comment has been minimized.

Copy link
Owner Author

FarbodSalamat-Zadeh commented Jan 17, 2016

@mcelotti - I have added the option for an error text for when the first item of the Spinner (e.g. a prompt, or hint) is selected, so the user knows it is an invalid selection.
See the changes in LabelledSpinner.java in the repo.

@paolorotolo - You mentioned that you would be willing to help on the project ;) . As you may (or may not) know, I have moved this to a repo. There are a few issues at the moment, so feel free to make a fork/pull request, or open an issue if you see an improvement/bug/etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.