Giter Site home page Giter Site logo

msvhora / awesomespinner Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sadra/awesomespinner

0.0 1.0 0.0 717 KB

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

Home Page: http://isapanah.com

License: Other

Java 100.00%

awesomespinner's Introduction

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.5.1'

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
getSelectedItemPosition() - Result = int: Returns the selected item position. If there were no selected item, it returns -1.
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.
setSpinnerHint(TEXT) String value You should pass a sting value as the hint text for the spinner.
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.
setHintTextColor() int Color If you need to change the Spinner Hint Text color, just call the method and pass you color, ex: Color.BLUE.
setSelectedItemHintColor() int Color If you need to change the Selected Item Hint color, just call the method and pass you color, ex: Color.BLUE.
setDownArrowTintColor() int Color If you need to change the Down Arrow hint color, just call the method and pass you color, ex: Color.BLUE.
setDropDownViewResource(RESOURCE) int Resource If you need to change the Spinner Row stype, just call the method and pass you resource, ex: R.layout.my_sipnner_row_item.
clearSelection() - It clears the spinner selection.

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

awesomespinner's People

Contributors

sadra avatar

Watchers

Murtaza S Vhora avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.