Skip to content

A Spinner component with a floating label for Android, similar to EditText components wrapped in a TextInputLayout.

License

Notifications You must be signed in to change notification settings

guitcastro/LabelledSpinner

 
 

Repository files navigation

LabelledSpinner

Build Status

A Spinner component with a floating label for Android, similar to EditText components wrapped in a TextInputLayout. It answers this question on Stack Overflow, and another similar question.

Gradle (Android Studio)

You can add this Android library to your Gradle dependencies.

To do so, add the following to your app module's build.gradle file:

dependencies {
    ...
    compile 'com.farbod.labelledspinner:labelledspinner:1.1.5'
}

Usage

Below is a basic example of how LabelledSpinner can be used. There is also a sample app you can view on this repository, showcasing LabelledSpinner's features in more detail.

XML layout file:

xmlns:ls="http://schemas.android.com/apk/res-auto"

...

<com.farbod.labelledspinner.LabelledSpinner
        android:id="@+id/your_labelled_spinner"
        ls:labelText="@string/your_spinner_label"
        ls:widgetColor="#F44336"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

And then in Java code...

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.example_usage);
    ...
    LabelledSpinner yourSpinner = (LabelledSpinner) findViewById(R.id.your_labelled_spinner);
    yourSpinner.setItemsArray(R.array.your_array);
    yourSpinner.setOnItemChosenListener(this);
}

@Override
public void onItemChosen(View labelledSpinner, AdapterView<?> adapterView, View itemView, int position, long id) {
    switch (labelledSpinner.getId()) {
        case R.id.your_labelled_spinner:
            // Do something here
            break;
        // If you have multiple LabelledSpinners, you can add more cases here
    }
}

@Override
public void onNothingChosen(View labelledSpinner, AdapterView<?> adapterView) {
    // Do something here
}

Changelog

A changelog of this repository can be found here, but see this page for a list of releases and tags (also with a changelog).

Copyright

Copyright 2015-2016 Farbod Salamat-Zadeh

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

A Spinner component with a floating label for Android, similar to EditText components wrapped in a TextInputLayout.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%