VEINHORN / ScrollGalleryView

:bridge_at_night: Android image gallery with bottom scroll view
MIT License
531 stars 157 forks source link

Error scrollGalleryView.setOnScrollChangeListener #32

Closed firestork closed 6 years ago

firestork commented 8 years ago

I got error when I add this code :(

 scrollGalleryView.setOnScrollChangeListener(new OnScrollChangeListener() {
  @Override
  public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {

  }
 });
VEINHORN commented 8 years ago

@firestork Hi. Can you please provide more information about this error?

firestork commented 8 years ago

Hi, @VEINHORN! I declare a ScrollGalleryView in a FragmentActivity. show list image in my ArrayList- > ok well then I want get position when srcoll image. Here is my full code:

public class Gallery2Activity extends FragmentActivity {

 private int pos;
 private ArrayList < CarImage > listCarImage = new ArrayList < > ();
 private TextView textGallery;
 private ScrollGalleryView scrollGalleryView;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_gallery2);

  Intent intent = getIntent();
  listCarImage = (ArrayList < CarImage > ) intent
   .getSerializableExtra("listcar");

  pos = intent.getIntExtra("pos", -1);

  textGallery = (TextView) findViewById(R.id.textGallery);
  List < MediaInfo > infos = new ArrayList < > (listCarImage.size());
  //for (String url : images) infos.add(MediaInfo.mediaLoader(new PicassoImageLoader(url)));

  for (CarImage car: listCarImage) {
   infos.add(MediaInfo.mediaLoader(new PicassoImageLoader(getString(R.string.url_image) + car.getImage())));
  }
  scrollGalleryView = (ScrollGalleryView) findViewById(R.id.scroll_gallery_view);
  scrollGalleryView
   .setThumbnailSize(100)
   .setZoom(true)
   .setFragmentManager(getSupportFragmentManager())
   .addMedia(infos);
  if (pos != -1) {
   scrollGalleryView.setCurrentItem(pos);
  }
  scrollGalleryView.setOnScrollChangeListener(new OnScrollChangeListener() {
   @Override
   public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {

   }
  });
 }

 private Bitmap toBitmap(int image) {
  return ((BitmapDrawable) getResources().getDrawable(image)).getBitmap();
 }
}

And I got error:

> 04-05 14:18:13.791 1455-1455/com.vcomsat.gsht E/AndroidRuntime: FATAL EXCEPTION: main
>                                                                 Process: com.vcomsat.gsht, PID: 1455
>                                                                 java.lang.NoClassDefFoundError: com.vcomsat.gsht.activitys.Gallery2Activity$1
>                                                                     at com.vcomsat.gsht.activitys.Gallery2Activity.onCreate(Gallery2Activity.java:55)
>                                                                     at android.app.Activity.performCreate(Activity.java)
>                                                                     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java)
>                                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java)
>                                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java)
>                                                                     at android.app.ActivityThread.access$800(ActivityThread.java)
>                                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java)
>                                                                     at android.os.Handler.dispatchMessage(Handler.java)
>                                                                     at android.os.Looper.loop(Looper.java)
>                                                                     at android.app.ActivityThread.main(ActivityThread.java)
>                                                                     at java.lang.reflect.Method.invoke(Native Method)
>                                                                     at java.lang.reflect.Method.invoke(Method.java)
>                                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
>                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)

Error is occured on this line:

scrollGalleryView.setOnScrollChangeListener(new OnScrollChangeListener() {
firestork commented 8 years ago

import android.view.View.OnScrollChangeListener;

VEINHORN commented 8 years ago

@firestork View.OnScrollChangeListener was added in API level 23. Maybe you're trying to run that code using older API level, and so it cannot find that class.

firestork commented 8 years ago

@VEINHORN have any other way to get position when scroll?

firestork commented 8 years ago

@VEINHORN have no method addOnPageChangeListener in version 1.0.5. can u check this :dancers:

voghDev commented 7 years ago

+1. Would be really good to have a Listener to notify when pages are scrolled

Or alternatively, a getCurrentItem() method that lets you consult current page. I can submit you a PR with this last alternative if you want

VEINHORN commented 7 years ago

@voghDev thank you for your feedback. It would be nice if you'll provide PR.