Giter VIP home page Giter VIP logo

multiselectspinner's Introduction

Codacy Badge

MultiSelectSpinner

Android Library to Select multiple items from Spinner

Click to see video of example:

MultiSelectSpinner

How to import

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

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

Add dependency in build.gradle

implementation 'com.github.pratikbutani:MultiSelectSpinner:1.0.1'

Recent Changes

  • Added Material library.
  • Extracted the sample into a separate module.
  • Code cleanup.
  • position parameter is removed from both types of Spinner. Check comments above the code of setItems
  • selectAll button added to Select All Items in MultiSelectSpinner.
  • Code Optimised and Upgraded to latest versions of libraries/dependencies.
  • MOST IMP CHANGE You will get all the selected items in the listener instead of all items.

How to use SINGLE ITEM SELECTION

SINGLE ITEM SELECTION SPINNER (XML Code)

<com.androidbuts.multispinnerfilter.SingleSpinnerSearch
        android:id="@+id/singleItemSelectionSpinner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        app:hintText="Single Selection Spinner" />

SINGLE ITEM SELECTION SPINNER (Java Code)

    /******** MUST READ ALL COMMENTS AS DOCUMENTATION *********/
    /**
	 * Single Item Selection Spinner Demo
	 */
	SingleSpinnerSearch singleSpinnerSearch = findViewById(R.id.singleItemSelectionSpinner);

	// Pass true, If you want color separation. Otherwise false. default = false.
	singleSpinnerSearch.setColorseparation(true);

	// Pass true If you want searchView above the list. Otherwise false. default = true.
	singleSpinnerSearch.setSearchEnabled(true);

	// A text that will display in search hint.
	singleSpinnerSearch.setSearchHint("Select your mood");

	// Removed second parameter, position. Its not required now..
	// If you want to pass preselected items, you can do it while making listArray,
	// Pass true in setSelected of any item that you want to preselect
	// LOGICALLY, PASS Only One Item As SELECTED...
	singleSpinnerSearch.setItems(listArray0, new SingleSpinnerListener() {
		@Override
		public void onItemsSelected(KeyPairBoolData selectedItem) {
			Log.i(TAG, "Selected Item : " + selectedItem.getName());
		}

		@Override
		public void onClear() {
			Toast.makeText(MainActivity.this, "Cleared Selected Item", Toast.LENGTH_SHORT).show();
		}
	});

How to use MULTIPLE ITEM SELECTION SPINNER

MULTIPLE ITEM SELECTION SPINNER (XML Code)

<com.androidbuts.multispinnerfilter.MultiSpinnerSearch
	android:id="@+id/multipleItemSelectionSpinner"
	android:layout_width="match_parent"
	android:layout_height="wrap_content"
	android:layout_margin="10dp"
	app:hintText="Multi Item Selection" />

MULTIPLE ITEM SELECTION SPINNER (Java Code)

    /**
	 * Search MultiSelection Spinner (With Search/Filter Functionality)
	 *
	 *  Using MultiSpinnerSearch class
	 */
	MultiSpinnerSearch multiSelectSpinnerWithSearch = findViewById(R.id.multipleItemSelectionSpinner);

	// Pass true If you want searchView above the list. Otherwise false. default = true.
	multiSelectSpinnerWithSearch.setSearchEnabled(true);

	// A text that will display in search hint.
	multiSelectSpinnerWithSearch.setSearchHint("Select your mood");

	// Set text that will display when search result not found...
	multiSelectSpinnerWithSearch.setEmptyTitle("Not Data Found!");

	// If you will set the limit, this button will not display automatically.
	multiSelectSpinnerWithSearch.setShowSelectAllButton(true);

    	//A text that will display in clear text button
	multiSelectSpinnerWithSearch.setClearText("Close & Clear");
	
	// Removed second parameter, position. Its not required now..
	// If you want to pass preselected items, you can do it while making listArray,
	// Pass true in setSelected of any item that you want to preselect
	multiSelectSpinnerWithSearch.setItems(listArray1, new MultiSpinnerListener() {
		@Override
		public void onItemsSelected(List<KeyPairBoolData> items) {
			for (int i = 0; i < items.size(); i++) {
				if (items.get(i).isSelected()) {
					Log.i(TAG, i + " : " + items.get(i).getName() + " : " + items.get(i).isSelected());
				}
			}
		}
	});

	/**
	 * If you want to set limit as maximum item should be selected is 2.
	 * For No limit -1 or do not call this method.
	 *
	 */
	multiSelectSpinnerWithSearch.setLimit(2, new MultiSpinnerSearch.LimitExceedListener() {
		@Override
		public void onLimitListener(KeyPairBoolData data) {
			Toast.makeText(getApplicationContext(),
					"Limit exceed ", Toast.LENGTH_LONG).show();
		}
	});

Awesome contributors ๐Ÿคฉ

Made with contributors-img.

Buy a cup of coffee

If you found this project helpful or you learned something from the source code and want to thank me, consider buying me a cup of โ˜•๏ธ PayPal

Do not forget to give star if its useful to you. :)

multiselectspinner's People

Contributors

pratikbutani avatar mayursojitra avatar mohamedmoanes avatar leo6104 avatar ivancse58 avatar bismeetsingh avatar mustard avatar hrvamo avatar hussein-yassine avatar ketanvishwakarma avatar oi-narendra avatar therealtechwiz avatar codacy-badger avatar alnazer avatar irenilsonoliveira avatar meetmehdi avatar sneha3003 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.