Skip to content

Single Item Selection Spinner

Pratik Butani edited this page Sep 11, 2020 · 1 revision

How to use 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" />

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();
	}
});

That's it for Simple Single Item Selection :)

Thank you