Fragments in Android Kotlin

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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=".MainActivity"
android:orientation="vertical">

<Button
android:id="@+id/btn_show"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="show"/>

<FrameLayout
android:id="@+id/fragment_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>

</FrameLayout>
</LinearLayout>
val fram = supportFragmentManager.beginTransaction()
fram.add(R.id.fragment_main, fragment)
fram.commit()
val fram = supportFragmentManager.beginTransaction()
fram.replace(R.id.fragment_main, fragment)
fram.commit()
val fram = fragmentManager.beginTransaction()
fram.replace(R.id.fragment_main, fragment)
fram.commit()

--

--

--

Mobile App Developer and Trainer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Android Unity Game Development Blog, Day 6: Death To Drawing Hexagons (almost)

Android Lint Framework — An Introduction

This screenshot shows how android studio will pick up errors bases on our lint checks & provides a quick solution

Simplifying drag and drop

Enforcing Team Rules with Lint: Tests

The one and only object

Implementing Native Camera Plugin for Android!

Beware of Observer lambdas with Android LiveData

OpenCV on Android — Tiny with Optimization Enabled

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Satheesh Guduri

Satheesh Guduri

Mobile App Developer and Trainer

More from Medium

How to Implement Hilt in Android App?

Retrofit with ViewModel in Kotlin (Part-2)

Why Kotlin will replace Java for Android App Development

Understanding Kotlin Scope Functions for Android in 2 minutes