Android-Image-Slider icon indicating copy to clipboard operation
Android-Image-Slider copied to clipboard

setCurrentPageListener method not working

Open alejandro-piguave opened this issue 5 years ago • 1 comments

When I set the "setCurrentPageListener" of the Slider view it doesn't detect when the page is changed, this is my code in the onCreate method of my activity:

 if (getIntent().getExtras() != null) {
  int index = getIntent().getExtras().getInt("index", 0);
  final ArrayList < MediaInfo > mediaInfoList = getIntent().getExtras().getParcelableArrayList("mediaList");
  sliderView.setSliderAdapter(new SliderAdapter(mediaInfoList));
  sliderView.setCurrentPageListener(new CircularSliderHandle.CurrentPageListener() {
   @Override
   public void onCurrentPageChanged(int currentPosition) {
    //This never runs
    Toast.makeText(MediaActivity.this, "Current page" + currentPosition, Toast.LENGTH_SHORT).show();
    if (getSupportActionBar() != null) {
     getSupportActionBar().setTitle(mediaInfoList.get(currentPosition).getSenderName());
     getSupportActionBar().setSubtitle(String.valueOf(mediaInfoList.get(currentPosition).getTimestamp()));
    }
   }
  });
  sliderView.setCurrentPagePosition(index);
 }

And in the xml file: `<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".ui.activity.MediaActivity">

<com.smarteist.autoimageslider.SliderView
    android:id="@+id/imageSlider"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:sliderAutoCycleEnabled="false"
    app:sliderCircularHandlerEnabled="false"
    app:sliderIndicatorAnimationDuration="500"
    app:sliderIndicatorGravity="center_horizontal|bottom"
    app:sliderIndicatorMargin="15dp"
    app:sliderIndicatorOrientation="horizontal"
    app:sliderIndicatorPadding="3dp"
    app:sliderIndicatorRadius="2dp"
    app:sliderIndicatorSelectedColor="@color/colorPrimary"
    app:sliderIndicatorUnselectedColor="#FFF"
    app:sliderScrollTimeInSec="1" />

</LinearLayout>`

Everything else is working fine, the only issue I am having is this listener.

alejandro-piguave avatar Dec 06 '19 13:12 alejandro-piguave

When I set the "setCurrentPageListener" of the Slider view it doesn't detect when the page is changed, this is my code in the onCreate method of my activity:

 if (getIntent().getExtras() != null) {
  int index = getIntent().getExtras().getInt("index", 0);
  final ArrayList < MediaInfo > mediaInfoList = getIntent().getExtras().getParcelableArrayList("mediaList");
  sliderView.setSliderAdapter(new SliderAdapter(mediaInfoList));
  sliderView.setCurrentPageListener(new CircularSliderHandle.CurrentPageListener() {
   @Override
   public void onCurrentPageChanged(int currentPosition) {
    //This never runs
    Toast.makeText(MediaActivity.this, "Current page" + currentPosition, Toast.LENGTH_SHORT).show();
    if (getSupportActionBar() != null) {
     getSupportActionBar().setTitle(mediaInfoList.get(currentPosition).getSenderName());
     getSupportActionBar().setSubtitle(String.valueOf(mediaInfoList.get(currentPosition).getTimestamp()));
    }
   }
  });
  sliderView.setCurrentPagePosition(index);
 }

And in the xml file: `

<com.smarteist.autoimageslider.SliderView
    android:id="@+id/imageSlider"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:sliderAutoCycleEnabled="false"
    app:sliderCircularHandlerEnabled="false"
    app:sliderIndicatorAnimationDuration="500"
    app:sliderIndicatorGravity="center_horizontal|bottom"
    app:sliderIndicatorMargin="15dp"
    app:sliderIndicatorOrientation="horizontal"
    app:sliderIndicatorPadding="3dp"
    app:sliderIndicatorRadius="2dp"
    app:sliderIndicatorSelectedColor="@color/colorPrimary"
    app:sliderIndicatorUnselectedColor="#FFF"
    app:sliderScrollTimeInSec="1" />

`

Everything else is working fine, the only issue I am having is this listener.

Please update to 1.3.5 and tell me the result.

smarteist avatar Feb 16 '20 12:02 smarteist