Skip to content

Instantly share code, notes, and snippets.

@DavidInnocent
Last active May 12, 2020 16:50
Show Gist options
  • Save DavidInnocent/f44a27af2273f0ca9bed80cc3f60fc98 to your computer and use it in GitHub Desktop.
Save DavidInnocent/f44a27af2273f0ca9bed80cc3f60fc98 to your computer and use it in GitHub Desktop.
//OnboardingFragment
pagerAdapter=new OnboardingViewPagerAdapter(this);
viewPager2.setAdapter(pagerAdapter);
public class OnboardingViewPagerAdapter extends FragmentStateAdapter {
public OnboardingViewPagerAdapter(@NonNull Fragment fragment) {
super(fragment);
}
@NonNull
@Override
public Fragment createFragment(int position) {
if(position==0)
{
return new OnboardingScreen2Fragment();
}
else {
return new OnboardingScreen2Fragment();
}
}
@Override
public int getItemCount() {
return 2;
}
}
//Onboarding Fragment xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.co.ximmoz.FireFy.ui.views.Activities.MainActivity">
<androidx.viewpager2.widget.ViewPager2
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
//OnboardinfScreen1Fragment xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.co.ximmoz.FireFy.ui.views.Activities.MainActivity">
<!-- TODO: Update blank fragment layout -->
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Helloodsf "
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/Proceed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment