Skip to content
Browse files

Merge branch 'master' of git://github.com/SoftXperience/SwipeSelector…

… into SoftXperience-master
  • Loading branch information...
2 parents 19ceb58 + d63fe05 commit 7ecaf007aa7f7bc787a63caf8e95b384f86ad272 @roughike committed
View
22 swipe-selector/src/main/java/com/roughike/swipeselector/SwipeAdapter.java
@@ -281,6 +281,21 @@ protected SwipeItem getSelectedItem() {
return mItems.get(mCurrentPosition);
}
+ public void setSelectedItem(int position) {
+ if (position >= 0 && position < mItems.size()) {
+ mViewPager.setCurrentItem(position, true);
+ }
+ }
+
+ public void setSelectedItem(SwipeItem item) {
+ for (int i = 0; i < mItems.size(); i++) {
+ if (mItems.get(i).equals(item)) {
+ mViewPager.setCurrentItem(i, true);
+ break;
+ }
+ }
+ }
+
protected Bundle onSaveInstanceState() {
Bundle bundle = new Bundle();
bundle.putInt(STATE_CURRENT_POSITION, mCurrentPosition);
@@ -303,7 +318,12 @@ public Object instantiateItem(ViewGroup container, int position) {
SwipeItem slideItem = mItems.get(position);
title.setText(slideItem.title);
- description.setText(slideItem.description);
+ if (slideItem.description == null) {
+ description.setVisibility(View.GONE);
+ } else {
+ description.setVisibility(View.VISIBLE);
+ description.setText(slideItem.description);
+ }
// We shouldn't get here if the typeface didn't exist.
// But just in case, because we're paranoid.
View
8 swipe-selector/src/main/java/com/roughike/swipeselector/SwipeSelector.java
@@ -186,4 +186,12 @@ protected void dispatchSaveInstanceState(SparseArray<Parcelable> container) {
protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container) {
dispatchThawSelfOnly(container);
}
+
+ public void setSelectedItem(int position) {
+ mAdapter.setSelectedItem(position);
+ }
+
+ public void setSelectedItem(SwipeItem item) {
+ mAdapter.setSelectedItem(item);
+ }
}
View
14 swipe-selector/src/main/res/layout/swipeselector_content_item.xml
@@ -1,23 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
- android:orientation="vertical"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center_horizontal"
- xmlns:android="http://schemas.android.com/apk/res/android">
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:gravity="center"
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools">
<TextView
android:id="@+id/swipeselector_content_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
+ tools:text="Title"
android:textAppearance="@style/TextAppearance.AppCompat.Body2"/>
+
<TextView
android:id="@+id/swipeselector_content_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="4dp"
+ tools:text="Description"
android:textAppearance="@style/TextAppearance.AppCompat.Caption"/>
</LinearLayout>

0 comments on commit 7ecaf00

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