Skip to content

With Awesome Spinner you can implement a material spinner with access to define direction layout and hint text.

License

Notifications You must be signed in to change notification settings

biswanathgit/AwesomeSpinner

 
 

Repository files navigation

Awesome Android Spinner

License Dependencies Gitter Minimum Android SDK Version

With Awesome Spinner you can implement a material spinner with access to define direction layout and hint text.

Including the library

Step 1. Add it in your root build.gradle at the end of repositories:

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

Step 2. Add the dependency:

implementation 'com.github.sadra:AwesomeSpinner:1.1.0'

How To Use

Step 1. From very firts, you should add the Awsome Spinner component inside of your layout:

    <com.isapanah.awesomespinner.AwesomeSpinner
        android:id="@+id/my_spinner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
  • If you want to add a default value for hint just add the spinnerHint into your component
  • The default spinner has RTL direction, if you want to declare the direction of spinner just add the spinnerDirection to RTL or LTR so the complete example with LTR direction and hint text to Select a category is:
    <com.isapanah.awesomespinner.AwesomeSpinner
        android:id="@+id/my_spinner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:spinnerDirection="ltr"
        app:spinnerHint="Select a category" />

Step 2. Define the component class into your activity:

AwesomeSpinner my_spinner = (AwesomeSpinner) findViewById(R.id.my_spinner);

Then Create your adapter. For now, there is two way to define apadter:

  • With String List, define a List<String> in your activity and the attach that with your adapter:
List<String> categories = new ArrayList<String>();
categories.add("Automobile");
categories.add("Ariplane");

ArrayAdapter<String> categoriesAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, categories);

my_spinner.setAdapter(categoriesAdapter);
  • With String-Array, define a string-array in your strings.xml file and attach that with your adapter:
ArrayAdapter<CharSequence> provincesAdapter = ArrayAdapter.createFromResource(this, R.array.iran_provinces, android.R.layout.simple_spinner_item);

spinnerRTL.setAdapter(provincesAdapter, 0);

Step 3. For final step, you can create a Listener for listening on item selection:

my_spinner.setOnSpinnerItemClickListener(new AwesomeSpinner.onSpinnerItemClickListener<String>() {
    @Override
    public void onItemSelected(int position, String itemAtPosition) {
        //TODO YOUR ACTIONS
    }
});

Additional controls

there is some controls for your spinner:

Control Requierement Info
getSelectedItem() - Result = String: Returns the selected item
isSelected() - Result = boolean: Returns true if any item selected, and vice versa
setSelection(NUMBER) int position You should pass the position of item to select the item programatically
setSelection(TEXT) String value You should pass the item value to select the item programatically
setSpinnerEnable(BOOLEAN); Boolean value If you want enable or disable the spinner, you should call this method.
isSpinnerEnable(); - Result = boolean: Returns true if the spinner is enabled, and vice versa

You can see the EXAMPLE PROJECT for more infromation.

License

The MIT License (MIT): https://github.com/amlashi-sadra/AwesomeSpinner/blob/master/LICENSE

Copyright (c) 2017 Sadra Isapanah Amlashi

Website: isapanah.com

Twitter: @sadra_amlashi

About

With Awesome Spinner you can implement a material spinner with access to define direction layout and hint text.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%