Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] kotlin – Disable Smooth scroll when jump current item to another item in viewpager2 android

Posted on November 14, 2022

Solution 1 :

The second parameter of ViewPager.setCurrentItem funtion is boolean smoothScroll Try this:

mViewPager.setCurrentItem(15, false)

Problem :

Hey everyone I am new in android with kotlin. I have problem in viewpager2 which I cannot solve. I have one Mutable list in which 30 items data is present on it. When application opens I sat by default 15 index number data as default as index of viewpager2 as current item. If I move to page to 0 index then, I am reseting the Mutablelist data and adding 10 or 20 data on left and 0 index value set in the middle, which means I am shifting the data in which I am in successful. But the main problem is to disable the smooth scroll between 0 to 10-20 when I reset the list also I have observable variable as my current index which I am changing the current item of viewpager2.

private var b = false

 mViewPager.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
    override fun onPageScrolled(int position, float arg1, int arg2) {
            if(b){
                 if(position > 0 && position < 15){
                    mViewPager.setCurrentItem(currenIndex,false)
                    b = false
                 }
             }
    }
}

In Activity when I am resetting the mutable list or adding some value on it I changed the boolean value as true

 b = true

also in my observable code

currenIndex.observer(this, Observer {
 mViewPager.setCurrentItem(it, true)
})

It always jumping when resetting the list to 0,1,2,3,4,5,6,7,8,9,10.. and I want to disable all animation between them and only wanted to display the page directly 15 page

Also I tried to remove

mViewPager.setCurrentItem(it, true)

from my observable variable it works but their is some problem in between 0 and 1 the animation stops between them when first time to reaching index 0 without resetting the list.

Sorry for my English. Thanks in advance

READ  [ANSWERED] java - Android Studio Firebase extract query problems
Powered by Inline Related Posts

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress