1

I know this is a broad question but it goes as follows. I have a Fragment that lists TODO tasks. Now I want to add a swipe view - a second page - that lists the already completed tasks. So basically what I want to achieve looks like this:

Just imagine that there are two static pages "TODO" and "DONE"

This means that I need to share the data between the two screens. Also note that these two pages need to have a completely different layout.

I've done research and the brand new ViewPager2 seems to be the way to go. However, the official documentation doesn't really talk about my use case. They seem to have pages that use the same layout and don't share data between themselves: https://developer.android.com/guide/navigation/navigation-swipe-view-2

Since ViewPager2 is completely new I decided to post a Stackoverflow question right away due to the simple fact that I am positive that my use case is the most popular one and thus, there will be more people with the same question.

Summa summarum: How does one implement two Fragments - with independent layouts - that share data and are swipe views themselves by utilizing the new ViewPager2 library.

user123456789
  • 301
  • 1
  • 4
  • 15
  • use MVVM pattern and hold your data in ViewModel hosted inside your activity – Pawel Feb 06 '20 at 00:45
  • Thank you for your reply. I am using MVVM and the TODO-List is LiveData. I was wondering about the specific viewpager2 implementation for two static fragments. I am also happy if you can provide me with more documentation. – user123456789 Feb 06 '20 at 00:47
  • @Pawel alright thank you I got ViewPager2 working. However, the ViewModel that I use has unintended behaviour. I therefore openend a new question: https://stackoverflow.com/questions/60129178/viewpager2-tabs-problem-with-viewmodel-state – user123456789 Feb 08 '20 at 20:05
  • @Pawel Ok I am now 100% sure that my current problem is not related to the Pages themselves. Could you take a look ? Thanks https://stackoverflow.com/questions/60129178/viewpager2-tabs-problem-with-viewmodel-state – user123456789 Feb 16 '20 at 21:25

0 Answers0