GithubHelp home page GithubHelp logo

fragments-android's Introduction

Fragments Example

This project demonstrates the usage of multiple fragments within an Android application using Kotlin and ViewBinding. The project includes a MainActivity with three buttons to switch between different fragments (DefaultFragment, BlankFragment1, and BlankFragment2).

Project Structure

MainActivity

The MainActivity class initializes the default fragment (DefaultFragment) and sets up button click listeners to switch between BlankFragment1 and BlankFragment2. It uses ActivityMainBinding for ViewBinding to inflate the layout and bind the views.

Fragments

  1. DefaultFragment:

    • This is the initial fragment displayed when the application starts.
    • It inflates a simple layout with minimal logic.
  2. BlankFragment1:

    • Uses FragmentBlank1Binding for ViewBinding.
    • Includes a sample Toast message to indicate when the fragment is loaded.
  3. BlankFragment2:

    • A simple fragment that inflates its layout without additional logic.

Layout Files

  1. activity_main.xml:

    • Contains a FrameLayout with the ID frameLayout to host the fragments.
    • Includes two buttons with IDs button1 and button2 to switch between the fragments.
  2. fragment_default.xml:

    • Layout for DefaultFragment.
    • Contains a TextView displaying "Default Fragment".
  3. fragment_blank1.xml:

    • Layout for BlankFragment1.
    • Contains a TextView displaying "Blank Fragment 1".
  4. fragment_blank2.xml:

    • Layout for BlankFragment2.
    • Contains a TextView displaying "Blank Fragment 2".

Usage

  1. Setup Android Studio:

    • Open the project in Android Studio.
  2. Run the App:

    • Execute the app on an emulator or physical device.
  3. Switch Fragments:

    • Use the buttons in MainActivity to switch between DefaultFragment, BlankFragment1, and BlankFragment2.

Dependencies

  • AndroidX: Ensure your project is using AndroidX libraries for compatibility.
  • ViewBinding: Used for binding views in MainActivity and BlankFragment1.

Notes

  • The default fragment (DefaultFragment) is displayed when the app starts.
  • Clicking the buttons will replace the current fragment with BlankFragment1 or BlankFragment2.
  • BlankFragment1 includes a Toast message to indicate its loading for demonstration purposes.

fragments-android's People

Contributors

devanshsati avatar

Watchers

 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.