-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
<resources> | ||
<string name="app_name">Untriggered</string> | ||
<string-array name="fruits"> | ||
<item>Apple</item> | ||
<item>Orange</item> | ||
<item>Banana</item> | ||
</string-array> | ||
</resources> |
45 changes: 45 additions & 0 deletions
45
untriggered/src/main/java/com/commit451/untriggered/UntriggeredSpinner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.commit451.untriggered; | ||
|
||
import android.content.Context; | ||
import android.support.v7.widget.AppCompatSpinner; | ||
import android.util.AttributeSet; | ||
|
||
/** | ||
* {@link AppCompatSpinner} that allows you to set the check state without triggering the | ||
* {@link android.widget.CompoundButton.OnCheckedChangeListener} | ||
*/ | ||
public class UntriggeredSpinner extends AppCompatSpinner { | ||
|
||
OnItemSelectedListener onItemSelectedListener; | ||
|
||
public UntriggeredSpinner(Context context) { | ||
super(context); | ||
} | ||
|
||
public UntriggeredSpinner(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
} | ||
|
||
public UntriggeredSpinner(Context context, AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
} | ||
|
||
@Override | ||
public void setOnItemSelectedListener(OnItemSelectedListener onItemSelectedListener) { | ||
super.setOnItemSelectedListener(onItemSelectedListener); | ||
this.onItemSelectedListener = onItemSelectedListener; | ||
} | ||
|
||
/** | ||
* Set the selection without triggering the registered {@link android.widget.AdapterView.OnItemSelectedListener} | ||
* @param selection selection | ||
* @param animate if you want it to animate | ||
* @see {@link #setSelection(int, boolean)} | ||
*/ | ||
public void setSelectionUntriggered(int selection, boolean animate) { | ||
OnItemSelectedListener currentListener = onItemSelectedListener; | ||
setOnItemSelectedListener(null); | ||
setSelection(selection, animate); | ||
setOnItemSelectedListener(currentListener); | ||
} | ||
} |