Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong position of recyclerview items #49

Closed
gssinghgautam opened this issue Nov 27, 2016 · 10 comments
Closed

Wrong position of recyclerview items #49

gssinghgautam opened this issue Nov 27, 2016 · 10 comments

Comments

@gssinghgautam
Copy link

when ads are not loading in recyclerview the position of the item on click is wrong ..its not giving me the correct value

@kot331107
Copy link
Contributor

kot331107 commented Nov 27, 2016

@gssinghgautam We'll check it a bit later and return back to you...

@gssinghgautam
Copy link
Author

can you please check the error, why its giving wrong position when ads are not visible

@aa-contorra
Copy link

@gssinghgautam I'm also facing same issue when trying to get pos like this https://github.com/clockbyte/admobadapter/wiki/Cookbook#in-case-you-stucked-with-getting-the-correct-itemindex-of-a-source-collection-in-a-listviewrecyclerview-click-handler
so it's look like method getOriginalContentPosition() works wrong. You can use this workaround:

int fetchedAdsCnt = adapterWrapper.getFetchedAdsCount();
int originalPos; 
  if (fetchedAdsCnt > 0) {\\we have some ads, need to use adapterCalc's method
      int sourceCnt = adapterWrapper.getAdapter().getCount();
      originalPos = adapterCalc.getOriginalContentPosition(position, fetchedAdsCnt, sourceCnt);
  } else { \\no ads, can use orignal pos
      originalPos = pos; \\if you are in onItemClick() method of ListView
     \\ originalPos = holder.getAdapterPosition(); \\ if you are in setOnClickListener of your RecycleView
  }

@kot331107
Copy link
Contributor

kot331107 commented Dec 7, 2016

@aa-contorra hi,

thx a lot for your contribution, we will include a fix for the getOriginalContentPosition() according to this issue to the next maven release.
Guys sorry for slow reaction, I haven't much time to support this lib at the moment.

KR

@kot331107 kot331107 added the bug label Dec 7, 2016
@aa-contorra
Copy link

aa-contorra commented Dec 12, 2016

also there is another bug here: while ads loading method getFetchedAdsCount() returns same value as for "no ads loaded" case, but adapter has placeholers with "ad id loading" text, so it's no way to get proper index of clicked element. Also it casuses IndexOfBounds exception in some cases...

@kot331107
Copy link
Contributor

kot331107 commented Dec 12, 2016

@aa-contorra I'm afraid at the moment you'd change the source of AdapterWrapper class a bit. Add the new method public int getFetchingAdsCount(){ return adFetcher.getFetchingAdsCount();} to AdapterWrapper and try to use it instead. It returns a size taking into account placeholders for ads...

@gssinghgautam
Copy link
Author

the workaround suggested by kot331107 is working fine

@aimiliano
Copy link

i suppose this is the same ? :

Exception java.lang.ArrayIndexOutOfBoundsException: length=36; index=36
android.widget.AbsListView$RecycleBin.addScrapView (AbsListView.java:8362)
android.widget.AbsListView.trackMotionScroll (AbsListView.java:6684)
android.widget.AbsListView$FlingRunnable.run (AbsListView.java:5750)
android.view.Choreographer$CallbackRecord.run (Choreographer.java:803)
android.view.Choreographer.doCallbacks (Choreographer.java:603)
android.view.Choreographer.doFrame (Choreographer.java:572)
android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:789)
android.os.Handler.handleCallback (Handler.java:733)
android.os.Handler.dispatchMessage (Handler.java:95)
android.os.Looper.loop (Looper.java:136)
android.app.ActivityThread.main (ActivityThread.java:5476)
java.lang.reflect.Method.invokeNative (Method.java)
java.lang.reflect.Method.invoke (Method.java:515)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1283)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1099)
dalvik.system.NativeStart.main (NativeStart.java)

@kot331107
Copy link
Contributor

@aimiliano don't think so. Please open a separate issue for that.

@kot331107
Copy link
Contributor

kot331107 commented Jan 21, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants