An instance-state saving fragment switcher, intended for use with navigation drawers or tabs.

Overview

FragmentSwitcher

FragmentSwitcher is an adapter-based, state-saving fragment container similar to a ViewPager.

It was designed with the NavigationDrawer and Tab patterns in mind but can be used anywhere that you switch between fragments and would like to retain instance state.

  • Retains instance state of Fragments even when removing them from your activity.
  • Compatible with existing adapters: FragmentPagerAdapter and FragmentStatePagerAdapter
  • Adapter determines fragment retention policy. See the documentation for the two adapters above.
  • Includes two new adapters: FragmentArrayPagerAdapter and FragmentStateArrayPagerAdapter. You no longer have to subclass PagerAdapter to use FragmentSwitcher, just supply an array of fragments.

The sample app shows a demo of a navigation drawer with a lot fragments in a FragmentStateArrayPagerAdapter that can maintain the state of an edittext and listview. The sample also includes an example of saving a ListView's adapter content to InstanceState and restoring it later.

Version History

1.1.0 (9/22/14)

  • Added setOnPageChangeListener(FragmentSwitcher.OnPageChangeListener listener)
  • Added support for generic fragment types in the FragmentSwitcher

1.0.0 (9/13/14)

  • Initial release

Usage

mFragmentSwitcher = (FragmentSwitcher) findViewById(R.id.fragment_switcher)
mFragmentAdapter = new FragmentStateArrayPagerAdapter(getSupportFragmentManager());
mFragmentSwitcher.setAdapter(mFragmentAdapter);
List<Fragment> fragments = Arrays.asList(fragment1, fragment2, fragment3);
mFragmentAdapter.addAll(fragments);
mFragmentSwitcher.setCurrentItem(2);

Download

Grab FragmentSwitcher with Gradle:

compile 'com.timehop.fragmentswitcher:library:1.1.2'

License

Copyright 2014 Jacob Tabak

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
You might also like...
BubbleTabBar is bottom navigation bar with customizable bubble like tabs
BubbleTabBar is bottom navigation bar with customizable bubble like tabs

BubbleTabBar BubbleTabBar is bottom navigation bar with customizable bubble like tabs Usage com.fxn.BubbleTabBar android:id="@+id/

BubbleTabBar is bottom navigation bar with customizable bubble like tabs
BubbleTabBar is bottom navigation bar with customizable bubble like tabs

BubbleTabBar BubbleTabBar is bottom navigation bar with customizable bubble like tabs Download AIX : Download Aix License Licensed under the Apache Li

A small navigation library for Android to ease the use of fragment transactions & handling backstack (also available for Jetpack Compose).
A small navigation library for Android to ease the use of fragment transactions & handling backstack (also available for Jetpack Compose).

A small navigation library for Android to ease the use of fragment transactions & handling backstack (also available for Jetpack Compose).

Android Navigation Fragment Share Element Example: Use Share Element Transition with recyclerView Item and ViewPager2 Item.
Android Navigation Fragment Share Element Example: Use Share Element Transition with recyclerView Item and ViewPager2 Item.

Android-Navigation-Fragment-Share-Element-Example 说明 Android 使用Navigation导航切换Fragment中使用共享元素过渡动画的例子:将在listFragment的RecyclerView的Item共享元素过渡到pagerFragme

[ACTIVE] Simple Stack, a backstack library / navigation framework for simpler navigation and state management (for fragments, views, or whatevers).
[ACTIVE] Simple Stack, a backstack library / navigation framework for simpler navigation and state management (for fragments, views, or whatevers).

Simple Stack Why do I want this? To make navigation to another screen as simple as backstack.goTo(SomeScreen()), and going back as simple as backstack

Tugas Fragment Codelab Navigation Pemrograman Mobile

AndroidTrivia - starter code Starter code for Android Kotlin Fundamentals codelab 3.1: Create and add a fragment. Introduction The AndroidTrivia app a

AndroidBriefActions - Android library for sending and observing non persistent actions such as showing a message; nice readable way to call navigation actions from ViewModel or Activity/Fragment.

implementation "com.vladmarkovic.briefactions:briefactions:$briefActionsVersion" Benefits Why use brief-actions library pattern: Prevent short-term ac

A progress wheel for android, intended for use instead of the standard progress bar.
A progress wheel for android, intended for use instead of the standard progress bar.

Deprecation warning This project is no-longer maintained, and has not been maintained for a few years now. If you're looking for an alternative librar

Strikt is an assertion library for Kotlin intended for use with a test runner such as JUnit, Minutest, Spek, or KotlinTest.

Strikt is an assertion library for Kotlin intended for use with a test runner such as JUnit, Minutest, Spek, or KotlinTest.

Kotlin CLI utilities, mostly intended for use with Clikt

Kotlin CLI Utils A repo containing basic CLI utilities for Kotlin. Installation dependencies { implementation("com.slack.cli:kotlin-cli-util:versio

Custom Tabs with Material Design effects
Custom Tabs with Material Design effects

MaterialTabs Custom Tabs with Material Design animations for pre-Lollipop devices       Download example apk It requires 14+ API and android support v

An Android Library to help you create actionbar tabs like
An Android Library to help you create actionbar tabs like "Capitaine train" app by Cyril Mottier

TabBarView An Android Library to help you create actionbar tabs like "Capitaine train" app by Cyril Mottier Implementation: Declare TabBarView and set

Custom Tabs with Material Design effects
Custom Tabs with Material Design effects

MaterialTabs Custom Tabs with Material Design animations for pre-Lollipop devices       Download example apk It requires 14+ API and android support v

Put some bubble in your tabs and give your apps a supa fresh style !
Put some bubble in your tabs and give your apps a supa fresh style !

BubbleTab Put some bubble in your tabs and give your apps a supa fresh style ! Usage Add a BubbleTab with your icons on the layout.xml Customisable pa

Android scrollable tabs
Android scrollable tabs

Scrollable is a library for an Android application to implement various scrolling technicks. It's all started with scrolling tabs, but now much more c

Show worldwide headline. API/Glide library/recycler view/volley library/kotlin/xml/ chrome custom tabs
Show worldwide headline. API/Glide library/recycler view/volley library/kotlin/xml/ chrome custom tabs

Show worldwide headline. API/Glide library/recycler view/volley library/kotlin/xml/ chrome custom tabs. - you can click on headline and it will open an article of that news in the app(no need to go to chrome or any browser)

Use Fragment like Activity
Use Fragment like Activity

Fragivity : Use Fragment like Activity English | 中文文档 Fragivity is a library used to build APP with "Single Activity + Multi-Fragments" Architecture R

Alert Dialog - You can use this extension instead of creating a separate Alert Dialog for each Activity or Fragment.
Alert Dialog - You can use this extension instead of creating a separate Alert Dialog for each Activity or Fragment.

We show a warning message (Alert Dialog) to the user in many parts of our applications. You can use this extension instead of creating a separate Alert Dialog for each Activity or Fragment. Thanks to this extension, you can create a Dialog and call it in the Activity or Fragment you want and customize the component you want.

This Project for how to use  MVVM , state flow, Retrofit, dagger hit, coroutine , use cases with Clean architecture.
This Project for how to use MVVM , state flow, Retrofit, dagger hit, coroutine , use cases with Clean architecture.

Clean-architecture This Project for how to use MVVM , state flow, Retrofit, dagger hit, coroutine , use cases with Clean architecture. Why i should us

Comments
  • Hashmaps

    Hashmaps

    Hi there, Love the library, use it frequently. Quick Q, what would I need to change make this functional with a HashMap<Integer, Fragment> as opposed to a collection (list/ Arraylist/ etc)? I already changed the code within the FragmentStateArrayPagerAdapter to mirror it, but I am unsure if I need to make changes also in just the FragmentSwitcher class or in multiple other ones too.

    opened by PGMacDesign 2
Owner
Jacob Tabak
Jacob Tabak
UpSchool Capstone Project - Course selling application with MVVM, LiveData, DataBinding, Retrofit, Room Database, Navigation Component, Adapter, Firebase Auth, Picasso, Lottie

UpSchool Capstone Project - Course selling application with MVVM (Model, View, ViewModel), LiveData, DataBinding, Retrofit, Room Database, Navigation Component(NavGraph, BottomNav), Adapter, Firebase Auth, Picasso, Lottie

Sena Çelik 5 Dec 21, 2022
Multitask、MultiThread(MultiConnection)、Breakpoint-resume、High-concurrency、Simple to use、Single/NotSingle-process

FileDownloader Android multi-task file download engine. 中文文档 FileDownloader2 Now, FileDownloader2-OkDownload is released, okdownload will contain all

LAIX Inc. (formerly LingoChamp Inc.) 10.7k Jan 3, 2023
****. Use the native and support library variants instead - https://developer.android.com/guide/topics/ui/look-and-feel/fonts-in-xml.html. An android library that makes it easy to add custom fonts to edittexts and textviews

Add to your project Add this line to your dependencies in build.gradle compile 'in.workarounds.typography:typography:0.0.8' Using the views There are

Workarounds 43 Nov 6, 2021
Highly experimental predefined Bootstrap functions to use in Compose Web

bootstrap-compose Highly experimental predefined Bootstrap functions to use in Compose Web Install This package is uploaded to MavenCentral. repositor

Philip Wedemann 45 Jan 6, 2023
Use your old Android device as an OctoPrint server.

Use your old Android device as an OctoPrint server.

Feelfree (Filip) 1k Dec 31, 2022
A small navigation library for Jetpack Compose with state saving, backstack and animations support.

A small navigation library for Jetpack Compose with state saving, backstack and animations support.

Xinto 5 Dec 27, 2022
Demonstration of a StrandHogg attack via the task switcher

StrandHogg attack recents App under attack android:launchMode="singleTask" Attacker app android:launchMode="singleTask" android:taskAffinity="com.exam

Jeroen Mols 2 Oct 25, 2021
Navigation in Android: Activity, Fragment, Intents, Navigation Component.

Words App This folder contains the source code for the Words app codelab. Introduction Words app allows you to select a letter and use Intents to navi

Shaima Alghamdi 2 Aug 15, 2022
An Android instance app for working with Google Map, Kotlin

map-instant-app An Android instance app Android technologies that I used: Name Description 1 Kotlin 2 Coroutine 3 Navigation 4 DataBinding 5 ViewBindi

Malihe 3 Nov 14, 2022
An Android instance app for working with Google Map, Kotlin

map-instance-app A map instance app for seeing the current position of the user and saving that in the database and showing a list of saved locations.

Malihe 2 Nov 3, 2022