Giter VIP home page Giter VIP logo

gaur171188 / recyclerviewtoviewpager Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rajashekarraju/recyclerviewtoviewpager

0.0 0.0 0.0 218 KB

ViewPager2 comes with major improvements from ViewPager which enables swipe views with RecyclerView, vertical swipe, orientation, right-to-left support, Modifiable fragment collection, PageTransformations, swipe between fragments with TabLayout, DiffUtils etc. Let's understand with an example implementation.

Home Page: https://developersbreach.com/recyclerview-to-viewpager2-materialviewpager-android/

Kotlin 100.00%

recyclerviewtoviewpager's Introduction

RecyclerViewToViewPager

Android app repository which demonstrates on imlementing RecyclerView to ViewPager2 along with jetpack components ViewModel, LiveData, NavigationComponent, Architecture.

ReyclerView to ViewPager

Dependencies

implementation "androidx.viewpager2:viewpager2:1.0.0"
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.navigation:navigation-fragment-ktx:2.2.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.2.2'
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"

Add ViewPager2 to xml layout

<androidx.viewpager2.widget.ViewPager2
    android:id="@+id/my_view_pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" />

ViewPager2 in Kotlin class

// Get reference to ViewPager2
val viewPager2: ViewPager2 = view.findViewById(R.id.detail_view_pager)
// Create a new ViewPagerAdapter class
val viewPagerAdapter = ViewPagerAdapter()
// Add items to our recyclerView adpater
viewPagerAdapter.submitList(yourItemsList)
// Attach ViewPager2 with Adapter
viewPager2.adapter = viewPagerAdapter
// Get user clicked item position and set it to ViewPager2
viewPager2.setCurrentItem(selectedItem)

Implementation has been clearly explained in blog (https://developersbreach.com)

This repository has following branches which differs in features stated below.

Branch - Master

Without DataBinding

Branch - DataBinding

Applied to ViewModels, Layouts, Fragment, Two-Way Binding

Branch - SimpleExample

No DataBiding, Removed Material ViewPager2, CustomViews Removed

recyclerviewtoviewpager's People

Contributors

rajashekarraju avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.