CREATING SWIPABLE VIEWS WITH VIEWPAGER 2 - Android Fundamentals

Поділитися
Вставка
  • Опубліковано 29 лис 2024

КОМЕНТАРІ • 131

  • @kopilkaiser8991
    @kopilkaiser8991 Рік тому +3

    A great job by you in being able to explain such a complicated topic so easily and making it easy to consume the concept of the new viewPager2

  • @abostef77
    @abostef77 4 роки тому +14

    TABLAYOUT WITH VIEWPAGER 2
    (go to previous video to understand)
    CREATING SWIPABLE VIEWS WITH VIEWPAGER 2
    (go to previous video about recycleview)
    The wheels on the bus go round and round
    round and round
    round and round
    All day long
    all day long.

  • @АркадийБардамов
    @АркадийБардамов 4 роки тому +7

    Thank you!
    I've started to learn Kotlin recently. You explained this material very well

  • @iftak01
    @iftak01 4 роки тому +2

    your the best man!! your just the best... Kotlin + all the new Android libraries....bless you!

  • @Diego17511
    @Diego17511 2 роки тому +2

    Great quality! Amazing job thank you so much
    I'm watching the playlist now, my only feedback to make things easier to understand is that you use labels that are very close to the syntax which can make it difficult to follow along at times, for example it would be easier to understand what is syntax and what is definable if you used silly names like "super duper button" & "second best button" instead of just "first button" & "second button"That contrast would make this already amazing tutorial series even better
    I hope that makes sense

  • @daiyrkanybekov8575
    @daiyrkanybekov8575 3 роки тому +2

    Great Tutorial! Hello from Bishkek, Kyrgyzstan

  • @starlite5097
    @starlite5097 4 роки тому +2

    Thanks for the hard work. I can support you like this. After I finish my thesis (a complex android app in kotlin) I will recommend your channel (among a few others) in 2 facebook groups from my country with software developers. Around 60k people in there, some of them would be interested.

    • @PhilippLackner
      @PhilippLackner  4 роки тому

      Thanks a lot for your support, glad my content helps you!!

  • @mandalsalman
    @mandalsalman 4 роки тому +3

    Impressive. You make look everything super easy.

  • @theodordimov6518
    @theodordimov6518 11 місяців тому

    Great tutorial. I think you might be missing a `viewPager = findViewById` instruction at around 9:52

  • @شاشةالمسلمالصغير
    @شاشةالمسلمالصغير 3 роки тому +3

    Nice tutorial, I have a question, please.
    How to change the swiping orientation to the left.
    (From the right to the left for Arabic app)
    Thank you

  • @Indently
    @Indently 4 роки тому +3

    Thanks for another great tutorial! Was just wondering if you could create a video that deals with interacting with the items in the viewpagers and recyclerviews (such as onClickListeners) perhaps in the near future? :)

    • @PhilippLackner
      @PhilippLackner  4 роки тому +2

      Hey man, thanks! If you want to interact with the items you can do that in the RecyclerView adapter in onBindViewHolder

    • @teunstout6725
      @teunstout6725 4 роки тому +1

      You can also pass a functrion with the adapter. Then you can make a onclick on the view itself now. Each time you press a onclick you can do a action defined in your "callback" function.

  • @norulesprateek
    @norulesprateek 4 роки тому

    Thought this would be very complex. Thanks a lot for making this easy.

  • @manishpingale6558
    @manishpingale6558 4 роки тому

    So glad that you use DARK THEME!!!!!!!!!!!!!!!!

  • @shareemteofilo6257
    @shareemteofilo6257 3 роки тому

    Thank you so much. This helped me a lot to understand view pager.

  • @dakopyc
    @dakopyc Рік тому +1

    Naming suggestion: For the "item" layout, instead of "item_view_pager" (which makes it sound like it contains or represents a ViewPager, not the item), I'd suggest maybe something like "view_pager_item" (or "pager_item" or "gallery_item", etc). Hope that helps! Thx for the videos... great summaries and review for me!

  • @nousernamethx
    @nousernamethx 3 роки тому

    Thank you, worked like a charm!

  • @GriNAME
    @GriNAME 2 роки тому

    Thank you so much!!! Quickly and easy :)

  • @mario33067
    @mario33067 3 роки тому

    this is an awesome channel! thks so much for every tutorial videos! it's helping a lot!

  • @lyawileh.a8741
    @lyawileh.a8741 4 роки тому

    Good explanation, thanks very much.

  • @PrashantKumar-je4bs
    @PrashantKumar-je4bs 2 роки тому +3

    Hey guys, I am using the latest android studio bumblebee 2021.1.1. In this version id of XML elements is not working. I have to use finfViewById() function for that. like in this tutorial viewPager.adepter is not working. the studio doesn't understand that pager. Any suggestion on this. please help me. Thanks.

    • @emmanuelsawe976
      @emmanuelsawe976 2 роки тому +1

      Same problem here.

    • @dirajnaik9869
      @dirajnaik9869 Рік тому

      findViewById(R.id.viewPager).adapter=adapter

    • @ahappyperson6530
      @ahappyperson6530 5 місяців тому

      for ActivityMain:
      class MainActivity : AppCompatActivity() {
      private lateinit var binding : ActivityMainBinding
      override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      enableEdgeToEdge()
      binding = ActivityMainBinding.inflate(layoutInflater)
      setContentView(binding.root)
      ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
      val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
      v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
      insets
      }
      val images = listOf(
      R.drawable.android,
      R.drawable.ss,
      R.drawable.ic_launcher_background
      )
      val adapter = ViewPagerAdapter(images)
      binding.viewPager.adapter = adapter
      }
      }
      For Adapter Class :
      class ViewPagerAdapter(
      val images : List
      ) : RecyclerView.Adapter() {
      private lateinit var bind : ItemViewPagerBinding
      inner class ViewPageViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
      override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewPageViewHolder {
      val view = LayoutInflater.from(parent.context).inflate(R.layout.item_view_pager, parent, false)
      bind = ItemViewPagerBinding.bind(view)
      return ViewPageViewHolder(view)
      }
      override fun onBindViewHolder(holder: ViewPageViewHolder, position: Int) {
      val curImage = images[position]
      holder.itemView.apply {
      bind.ivImage.setImageResource(curImage)
      }
      }
      override fun getItemCount(): Int {
      return images.size
      }
      }
      copy past this, it will work

  • @thyagonevessilvestre1248
    @thyagonevessilvestre1248 3 роки тому

    Saved my day, thanks.

  • @indignocat
    @indignocat Рік тому +1

    Refactoring `ViewPagerAdapter` with ViewBinding:
    class ViewPagerAdapter(
    private val images: List
    ) : RecyclerView.Adapter() {
    inner class ViewPagerViewHolder(val binding: ItemViewpagerBinding) :
    RecyclerView.ViewHolder(binding.root)
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewPagerViewHolder {
    val view = LayoutInflater.from(parent.context)
    val binding = ItemViewpagerBinding.inflate(
    view, parent, false
    )
    return ViewPagerViewHolder(binding)
    }
    override fun onBindViewHolder(holder: ViewPagerViewHolder, position: Int) {
    val currentImage = images[position]
    holder.binding.apply {
    ivImage.setImageResource(currentImage)
    }
    }
    override fun getItemCount(): Int {
    return images.size
    }
    }

    • @rehansyed89
      @rehansyed89 7 місяців тому

      What is ItemViewpagerBinding?

    • @indignocat
      @indignocat 7 місяців тому

      @@rehansyed89 It's the viewBinding class created for the binding if you've enabled viewBinding in build.gradle

  • @kevinbuguecio5673
    @kevinbuguecio5673 4 роки тому

    It really helped me mate, thanks!

  • @shohruhpulatov8616
    @shohruhpulatov8616 3 роки тому

    Thanks, very helpful!

  • @Dcutz
    @Dcutz 4 роки тому +1

    Great tutorial! if i wanted to make the viewpager keep going based on dates (yesterday, today, tomorow... etc) instead of the pictures, how would i do that?

  • @PrashantKumar-je4bs
    @PrashantKumar-je4bs 2 роки тому +4

    at 9:48 instead of using viewPager.adepter use this. findViewById(R.id.viewPager).adapter = adepter
    This will work....

  • @relaxtime6556
    @relaxtime6556 2 роки тому

    Nice, can plz share a way to use view binding in pager adapter? Thanks

  • @MohammadPourmami
    @MohammadPourmami 4 роки тому

    Great ! It was very useful to mr

  • @abostef77
    @abostef77 4 роки тому

    thanks for the video description implementaion :)

  • @MCA_HimanshuSeth
    @MCA_HimanshuSeth 4 роки тому

    Mind blowing 😎

  • @snailedlt
    @snailedlt 4 роки тому +4

    How can I combine this with the bottom navigation bar template, to get a swipeable view containing fragments?

    • @milomathew5267
      @milomathew5267 3 роки тому

      i guess Im pretty randomly asking but does anybody know of a good place to stream newly released movies online ?

    • @dominikmagnus5074
      @dominikmagnus5074 3 роки тому +1

      @Milo Mathew I watch on FlixZone. You can find it by googling :)

  • @henriquepetters
    @henriquepetters 4 роки тому +2

    Yo, dude! Great videos, glad i found you. Do you have some material on tablayout and fragments? Thanks for the great videos!

    • @PhilippLackner
      @PhilippLackner  4 роки тому +1

      Thanks man, yes I do! Take a look in this fundamentals Playlist, I have a separate video on each of those

  • @jdurefaccini
    @jdurefaccini 3 роки тому +1

    implementation 'com.google.android.material:material:1.3.0-beta01'

  • @ravisoni-ck8oo
    @ravisoni-ck8oo 3 роки тому

    Thanks for making video

  • @adolfochavez2021
    @adolfochavez2021 4 роки тому

    Thanks bro, it helped me a lot

  • @aryanvikash1967
    @aryanvikash1967 4 роки тому

    No .. It's not a viewpager it just a another recyclerview 🤪😂
    Great tutorial 🔥🔥

  • @bhupeshpattanaik7150
    @bhupeshpattanaik7150 3 роки тому +1

    I have used viewpager2 to change fragment, but I don't know how to change the title of title bar of my activity as I swipe to other activity, I know I need to use toolbar.title="frag1" but don't know where to use that ☹️😟😕 ..... Please guide

  • @jude-l3f
    @jude-l3f 4 роки тому +1

    You're awesome 👌

  • @siddharthaghosal2146
    @siddharthaghosal2146 4 роки тому

    Thank you for the great content and explanation. It worked! :-D

  • @themessias
    @themessias 4 роки тому

    Great tutorial!, it is possible to preview of the image on both the left and the right? thanks!

  • @os4_official
    @os4_official 2 роки тому

    Thanks, bro

  • @ImaTheSeller-
    @ImaTheSeller- 3 роки тому

    Does this viewpager2 works similary with a BarLayout as the old Viewpager??

  • @manishpingale6558
    @manishpingale6558 4 роки тому +1

    Sir, can we just use horizontal Recycler view instead of using viewpager?

    • @PhilippLackner
      @PhilippLackner  4 роки тому +1

      Then you don't have the swiping functionality, instead you can scroll

    • @manishpingale6558
      @manishpingale6558 4 роки тому

      @@PhilippLackner ohh yeah got it 👍👍👍👍 thank you 🙏🙏🙏🙏🤗🤗🤗 great content watching your all series. 🤗

  • @alexissuarezalvarez5622
    @alexissuarezalvarez5622 2 роки тому

    Hello thank you very much for the content, I am trying to implement viewpager2 with jetpack, I don't use images but videos. This does not work correctly because the videos play once (others don't) and then simply none of them can play, do you know why this happens or how can I fix it?

  • @kirbi8864
    @kirbi8864 3 роки тому

    How 2 swipe activities to left/right like overlapped game cards and with slight arc trajectory ?

  • @valarmorghulisx
    @valarmorghulisx 4 роки тому

    Thank you for great videos. What is the fake dragging? and what is it used for? i understand that was changed image programatically. but it was in just create function and i couldnt imagine which area it is using.

    • @PhilippLackner
      @PhilippLackner  4 роки тому +1

      Might be useful if you have additional controls such as a next and previous button and you want the viewpager to swipe if you click on these buttons

    • @PhilippLackner
      @PhilippLackner  4 роки тому +1

      Might be useful if you have additional controls such as a next and previous button and you want the viewpager to swipe if you click on these buttons

    • @TheImaginativeSachin
      @TheImaginativeSachin 2 роки тому

      @@PhilippLackner interesting

  • @jinayshah798
    @jinayshah798 Рік тому +1

    Can anyone please explain the functioning of fakeDrag, like what happens while implementing it?

    • @Luffy_2804
      @Luffy_2804 Рік тому +1

      use : when we set the offset (give a particular value) it means that while swapping how many images will scroll in one swap (in simpler words how fast the image can be scrolled in one swipe) do you get it

  • @sabirfitvlogs1408
    @sabirfitvlogs1408 2 роки тому

    I created viewpager and inside that viewpager i loaded few fragment inside those fragments there are webviews . When iam scrolling that webview vertical it scrolls but not smoothly some time viewpager gets swiped. And though webview can be horizontally scrolled but it is not scrolling instead the viewpager is getting swiped. Please help me with this.

  • @frozen1093
    @frozen1093 3 роки тому

    seems cool man

  • @rabiakhalid2158
    @rabiakhalid2158 Рік тому

    Can we these images from right to left?

  • @olatosin3703
    @olatosin3703 4 роки тому

    Thanks for the video. You're really amazing.
    I have a very complicated question I'd be really glad if you can help.
    Let's say I have up to a hundred images to swipe in my drawable folder. After clicking a button from an activity, it goes to a specific image number for example...image 21 instead of the 1st image, and the swiping starts from there. How do I implement that.
    I'd be glad if you can explain in java and not kotlin and if not, I will find my away around the concept. Thanks for your effort.

    • @PhilippLackner
      @PhilippLackner  4 роки тому +1

      There is a function for viewpager called scrollToPosition which will do what the name says :D

    • @olatosin3703
      @olatosin3703 4 роки тому

      @@PhilippLackner Oh ok.. I'll check it out. Thank you

    • @marwaeltayeb
      @marwaeltayeb 2 роки тому

      @@PhilippLackner This method scrollToPosition is not found. Can you help?

  • @davidc4155
    @davidc4155 Рік тому

    I follow step by step but i can't get it to work. has something changed for Flamingo? it doesn't recognize ivImage in the override fun onBindViewHolder and it doesn't recognize the viewPager.adapter = adapter. help would be appreciated

    • @sergheiN
      @sergheiN 11 місяців тому

      findViewById(R.id.viewPager).adapter = adapter

    • @sergheiN
      @sergheiN 11 місяців тому

      as far I understand, author uses some plugin for Android Studio and that's why he can access identifiers in a such way 🙂

  • @starlite5097
    @starlite5097 4 роки тому

    I searched through many videos, but I didn't find one in kotlin where someone selects multiple images from the gallery and displays them inside a recycler view. How should I pass the images from onActivityResult to the recycler view with data-binding? Should I include mvvm too? :D

    • @starlite5097
      @starlite5097 4 роки тому

      I put your code with the adapter from onCreate to onResume and it works when uploading multiple images. Too bad I don't know if I can do that with data-binding

  • @ASININEMedia
    @ASININEMedia 4 роки тому

    Hi, I tried to add dot indicator using TabsLayout and TabLayoutMediator. but its not showing Can you help me

  • @gabrielvisiedopelaez2113
    @gabrielvisiedopelaez2113 3 роки тому

    How I can load the images using Glide? is it posible in this example?

  • @bryanguerra7094
    @bryanguerra7094 4 роки тому

    Is there any way now where you can zoom in to those images all while maintaining viewpager? I really want to learn how to have both features at the same time.

  • @Aleinux
    @Aleinux 4 роки тому +1

    And if I want an auto slideshow and infinite loop? How I have to do? Thanks

    • @PhilippLackner
      @PhilippLackner  4 роки тому

      Then you need to always replace the next item in the recyclerview with the item you want to have next. And everytime the user swipes you replace the next one again (and the last one of course)

  • @harshitsrivastava9903
    @harshitsrivastava9903 4 роки тому

    Thanks a lot

  • @brucewayne7909
    @brucewayne7909 4 роки тому +1

    Hello Brother,
    Thanks for the awesome tutorial. I just have a small issue.... I've uploaded 6 images. The scroll is smooth for the first 3 images, but then it starts to lag when I try to scroll to the next 3 images. What could be the reason bro?
    Thanks in advance :-)

    • @humbleson7237
      @humbleson7237 4 роки тому +2

      try using small size images, big size images often leads to buffer that leads to slowing up performance

  • @ruturajghumkar
    @ruturajghumkar 2 роки тому

    Hello thanks for this tutorial it would be great if you provide the code of every tutorial !!

  • @ayushsinha4815
    @ayushsinha4815 3 роки тому

    How to add both horizontal and vertical swapping in view pager 2

  • @VarunPrasadoneplusone
    @VarunPrasadoneplusone Рік тому

    Please add dependency in description

    • @Luffy_2804
      @Luffy_2804 Рік тому

      no need dude , now we can implement it in xml directly

  • @javidsattar281
    @javidsattar281 4 роки тому

    How can we use several different fragments?

  • @coc3629
    @coc3629 Рік тому

    I have implemented it using view binding feature but I am having a problem that in the application on swiping some images reappear and some images didn't even appear i.e not every image is appearing exactly once please help me with it.....

    • @Luffy_2804
      @Luffy_2804 Рік тому

      how's journey going bro ? developed some apps or not ?

  • @mustafakorkmaz5702
    @mustafakorkmaz5702 4 роки тому

    Since kotlin-android-extenstions are deprecated, I couldn't do the holder.itemView.ivImage.setImageResource(curImage) part. Any suggestions for how to do it?

    • @PhilippLackner
      @PhilippLackner  4 роки тому +1

      ViewBinding

    • @mustafakorkmaz5702
      @mustafakorkmaz5702 4 роки тому

      @@PhilippLackner Thanks I'm trying to learn ViewBinding

    • @berkayozgen259
      @berkayozgen259 3 роки тому

      @@mustafakorkmaz5702 Merhaba kardeşim, çözüm bulabildin mi?

    • @mustafakorkmaz5702
      @mustafakorkmaz5702 3 роки тому

      @@berkayozgen259 bulamadım maalesef

    • @indignocat
      @indignocat Рік тому

      I've found a way to refactor the `ViewPagerAdapter` class using ViewBinding:
      class ViewPagerAdapter(
      private val images: List
      ) : RecyclerView.Adapter() {
      inner class ViewPagerViewHolder(val binding: ItemViewpagerBinding) :
      RecyclerView.ViewHolder(binding.root)
      override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewPagerViewHolder {
      val view = LayoutInflater.from(parent.context)
      val binding = ItemViewpagerBinding.inflate(
      view, parent, false
      )
      return ViewPagerViewHolder(binding)
      }
      override fun onBindViewHolder(holder: ViewPagerViewHolder, position: Int) {
      val currentImage = images[position]
      holder.binding.apply {
      ivImage.setImageResource(currentImage)
      }
      }
      override fun getItemCount(): Int {
      return images.size
      }
      }

  • @madhan6816
    @madhan6816 4 роки тому

    how to add buttons on viewpager. ex like btn.

  • @denisk3852
    @denisk3852 3 роки тому

    How to implement an infinity swiper?

  • @RockoShaw
    @RockoShaw 4 роки тому +1

    I couldn't continue with the tutorial at the part of the ViewPagerAdapter creation because it's made in Kotlin. I tried to understand how it works to make it on Java but I couldn't. I tried extending RecyclerView.ViewHolder but there are no methods to override.
    It would be good if you added to your video title "With Kotlin" so people like me that doesn't want to move away from JAVA can stay away or at least be prepared....
    Thanks

    • @PhilippLackner
      @PhilippLackner  4 роки тому +4

      You can clearly see the kotlin icon in the video thumbnail

  • @maasiliy2002
    @maasiliy2002 4 роки тому

    How use two or more ViewPager?

  • @mlktech1531
    @mlktech1531 4 роки тому

    Hi how can i go from right to letf

  • @ezequieladrianminniti6252
    @ezequieladrianminniti6252 4 роки тому +1

    i was wondering why from nothing switched to kotlin

  • @jovianswank300
    @jovianswank300 3 роки тому

    what about cardview ????

  • @NickMirambeau
    @NickMirambeau 3 роки тому

    **spends all night translating this into java somehow**

  • @bivinoc3804
    @bivinoc3804 4 роки тому

    How to find last swipe in viewpager 2 ?

    • @PhilippLackner
      @PhilippLackner  4 роки тому +1

      just save the swipes and then check accordingly

  • @wesleytany.s3247
    @wesleytany.s3247 4 роки тому

    Can someone help D: the $kotlin_version does not work and does not sync at all

  • @arpitgupta3151
    @arpitgupta3151 4 роки тому

    My app is crashing after swiping last image

  • @claudiuhaidu3453
    @claudiuhaidu3453 2 роки тому +2

    How do you get the image view without findViewById() at 08:39, you call holder.itemVIew.ivImage directly ?!?!

    • @ahappyperson6530
      @ahappyperson6530 5 місяців тому

      use viewBinding bro, findByView is old so dont use it, direct use of ivImage is deprecated so use viewBinding

  • @1noob369
    @1noob369 3 роки тому

    Where is the code Bro!

  • @mohameddarwish1347
    @mohameddarwish1347 4 роки тому

    i get this(Pages must fill the whole ViewPager), i tried a lot of solution even i watch the vido agin but still get it

  • @DilpreetSingh-pd6co
    @DilpreetSingh-pd6co 3 роки тому

    plzz upload with java