Skip to content
Browse files

Now throwing exceptions if the item selection fails, just because exc…

…eptions are fun.
  • Loading branch information...
1 parent 0b0e152 commit 889f5a83ede7b616a0e490f7c2b37fcd77842059 @roughike committed
Showing with 14 additions and 2 deletions.
  1. +14 −2 swipe-selector/src/main/java/com/roughike/swipeselector/SwipeAdapter.java
View
16 swipe-selector/src/main/java/com/roughike/swipeselector/SwipeAdapter.java
@@ -282,18 +282,30 @@ protected SwipeItem getSelectedItem() {
}
public void selectItemAt(int position, boolean animate) {
- if (position >= 0 && position < mItems.size()) {
- mViewPager.setCurrentItem(position, animate);
+ if (position < 0 || position >= mItems.size()) {
+ throw new IndexOutOfBoundsException("This SwipeSelector does " +
+ "not have an item at position " + position + ".");
}
+
+ mViewPager.setCurrentItem(position, animate);
}
public void selectItemWithValue(Object value, boolean animate) {
+ boolean itemExists = false;
+
for (int i = 0; i < mItems.size(); i++) {
if (mItems.get(i).value.equals(value)) {
mViewPager.setCurrentItem(i, animate);
+ itemExists = true;
break;
}
}
+
+ if (!itemExists) {
+ throw new IllegalArgumentException("This SwipeSelector " +
+ "does not have an item with the given value "
+ + value.toString() + ".");
+ }
}
protected Bundle onSaveInstanceState() {

0 comments on commit 889f5a8

Please sign in to comment.
Something went wrong with that request. Please try again.